diff options
| author | Wei Mi <wmi@google.com> | 2018-05-01 14:47:24 +0000 |
|---|---|---|
| committer | Wei Mi <wmi@google.com> | 2018-05-01 14:47:24 +0000 |
| commit | eec5ba9faea38b911cdd8aaf48cde1bd2e194be4 (patch) | |
| tree | f198ba8fbc56f21bcb1ac84eb14fd86ea2ae2612 /llvm/lib/Transforms | |
| parent | 54596e1c1a1b1579ab54f4e55cf51a61d10be27d (diff) | |
| download | bcm5719-llvm-eec5ba9faea38b911cdd8aaf48cde1bd2e194be4.tar.gz bcm5719-llvm-eec5ba9faea38b911cdd8aaf48cde1bd2e194be4.zip | |
Fix the issue that ComputeValueKnownInPredecessors only handles the case when
phi is on lhs of a comparison op.
For the following testcase,
L1:
%t0 = add i32 %m, 7
%t3 = icmp eq i32* %t2, null
br i1 %t3, label %L3, label %L2
L2:
%t4 = load i32, i32* %t2, align 4
br label %L3
L3:
%t5 = phi i32 [ %t0, %L1 ], [ %t4, %L2 ]
%t6 = icmp eq i32 %t0, %t5
br i1 %t6, label %L4, label %L5
We know if we go through the path L1 --> L3, %t6 should always be true. However
currently, if the rhs of the eq comparison is phi, JumpThreading fails to
evaluate %t6 to true. And we know that Instcombine cannot guarantee always
canonicalizing phi to the left hand side of the comparison operation according
to the operand priority comparison mechanism in instcombine. The patch handles
the case when rhs of the comparison op is a phi.
Differential Revision: https://reviews.llvm.org/D46275
llvm-svn: 331266
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/JumpThreading.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 29c707799bd..4e02fc7da20 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -752,6 +752,8 @@ bool JumpThreadingPass::ComputeValueKnownInPredecessors( CmpInst::Predicate Pred = Cmp->getPredicate(); PHINode *PN = dyn_cast<PHINode>(CmpLHS); + if (!PN) + PN = dyn_cast<PHINode>(CmpRHS); if (PN && PN->getParent() == BB) { const DataLayout &DL = PN->getModule()->getDataLayout(); // We can do this simplification if any comparisons fold to true or false. @@ -762,14 +764,24 @@ bool JumpThreadingPass::ComputeValueKnownInPredecessors( LVI->enableDT(); for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) { BasicBlock *PredBB = PN->getIncomingBlock(i); - Value *LHS = PN->getIncomingValue(i); - Value *RHS = CmpRHS->DoPHITranslation(BB, PredBB); - + Value *LHS, *RHS; + if (PN == CmpLHS) { + LHS = PN->getIncomingValue(i); + RHS = CmpRHS->DoPHITranslation(BB, PredBB); + } else { + LHS = CmpLHS->DoPHITranslation(BB, PredBB); + RHS = PN->getIncomingValue(i); + } Value *Res = SimplifyCmpInst(Pred, LHS, RHS, {DL}); if (!Res) { if (!isa<Constant>(RHS)) continue; + // getPredicateOnEdge call will make no sense if LHS is defined in BB. + auto LHSInst = dyn_cast<Instruction>(LHS); + if (LHSInst && LHSInst->getParent() == BB) + continue; + LazyValueInfo::Tristate ResT = LVI->getPredicateOnEdge(Pred, LHS, cast<Constant>(RHS), PredBB, BB, |

