From 2f27456c826a9266f8f3e9cefafd1f7e08ab51b1 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Wed, 18 Oct 2017 22:00:57 +0000 Subject: [PATCH] Revert "[ScalarEvolution] Handling for ICmp occuring in the evolution chain." This reverts commit r316054. There was some confusion over the review process: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20171016/495884.html llvm-svn: 316129 --- llvm/include/llvm/Analysis/ScalarEvolution.h | 3 -- llvm/lib/Analysis/ScalarEvolution.cpp | 45 ++----------------- .../Transforms/Scalar/LoopStrengthReduce.cpp | 7 +-- llvm/test/Analysis/ScalarEvolution/pr34538.ll | 19 -------- 4 files changed, 5 insertions(+), 69 deletions(-) delete mode 100644 llvm/test/Analysis/ScalarEvolution/pr34538.ll diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h index af54e536277c..3190e7f56cfe 100644 --- a/llvm/include/llvm/Analysis/ScalarEvolution.h +++ b/llvm/include/llvm/Analysis/ScalarEvolution.h @@ -1378,9 +1378,6 @@ private: /// Helper function called from createNodeForPHI. const SCEV *createAddRecFromPHI(PHINode *PN); - /// Evaluate ICmpInst to a constant node for special patterns. - const SCEV *evaluateForICmp(ICmpInst *IC); - /// A helper function for createAddRecFromPHI to handle simple cases. const SCEV *createSimpleAffineAddRec(PHINode *PN, Value *BEValueV, Value *StartValueV); diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index e872e81a5e7c..c69bd601aff3 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -4756,26 +4756,11 @@ const SCEV *ScalarEvolution::createAddRecFromPHI(PHINode *PN) { Ops.push_back(Add->getOperand(i)); const SCEV *Accum = getAddExpr(Ops); - bool InvariantF = isLoopInvariant(Accum, L); - - if (!InvariantF && Accum->getSCEVType() == scZeroExtend) { - const SCEV *Op = dyn_cast(Accum)->getOperand(); - const SCEVUnknown *Un = dyn_cast(Op); - if (Un && Un->getValue() && isa(Un->getValue()) && - dyn_cast(Un->getValue())->getOpcode() == - Instruction::ICmp) { - const SCEV *ICmpSC = evaluateForICmp(cast(Un->getValue())); - bool IsConstSC = ICmpSC->getSCEVType() == scConstant; - Accum = - IsConstSC ? getZeroExtendExpr(ICmpSC, Accum->getType()) : Accum; - InvariantF = IsConstSC ? true : false; - } - } - // This is not a valid addrec if the step amount is varying each // loop iteration, but is not itself an addrec in this loop. - if (InvariantF || (isa(Accum) && - cast(Accum)->getLoop() == L)) { + if (isLoopInvariant(Accum, L) || + (isa(Accum) && + cast(Accum)->getLoop() == L)) { SCEV::NoWrapFlags Flags = SCEV::FlagAnyWrap; if (auto BO = MatchBinaryOp(BEValueV, DT)) { @@ -6458,30 +6443,6 @@ void ScalarEvolution::forgetLoop(const Loop *L) { } } - -const SCEV *ScalarEvolution::evaluateForICmp(ICmpInst *IC) { - BasicBlock *Latch = nullptr; - const Loop *L = LI.getLoopFor(IC->getParent()); - - // If compare instruction is same or inverse of the compare in the - // branch of the loop latch, then return a constant evolution - // node. This shall facilitate computations of loop exit counts - // in cases where compare appears in the evolution chain of induction - // variables. - if (L && (Latch = L->getLoopLatch())) { - BranchInst *BI = dyn_cast(Latch->getTerminator()); - if (BI && BI->isConditional() && BI->getCondition() == IC) { - if (BI->getSuccessor(0) != L->getHeader()) - return getZero(Type::getInt1Ty(getContext())); - else - return getOne(Type::getInt1Ty(getContext())); - } - } - - return getUnknown(IC); -} - - void ScalarEvolution::forgetValue(Value *V) { Instruction *I = dyn_cast(V); if (!I) return; diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 01aa85edbb61..bbb179d3790c 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2969,11 +2969,8 @@ void LSRInstance::CollectChains() { // Ignore users that are part of a SCEV expression. This way we only // consider leaf IV Users. This effectively rediscovers a portion of // IVUsers analysis but in program order this time. - if (SE.isSCEVable(I.getType())) { - const SCEV *SI = SE.getSCEV(&I); - if (!isa(SI) && !isa(SI)) - continue; - } + if (SE.isSCEVable(I.getType()) && !isa(SE.getSCEV(&I))) + continue; // Remove this instruction from any NearUsers set it may be in. for (unsigned ChainIdx = 0, NChains = IVChainVec.size(); diff --git a/llvm/test/Analysis/ScalarEvolution/pr34538.ll b/llvm/test/Analysis/ScalarEvolution/pr34538.ll deleted file mode 100644 index 0aa72c36de4e..000000000000 --- a/llvm/test/Analysis/ScalarEvolution/pr34538.ll +++ /dev/null @@ -1,19 +0,0 @@ -; RUN: opt -S -scalar-evolution -loop-deletion -simplifycfg -analyze < %s | FileCheck %s --check-prefix=CHECK-ANALYSIS - -define i32 @foo() local_unnamed_addr #0 { -; CHECK-ANALYSIS: Loop %do.body: backedge-taken count is 10000 -; CHECK-ANALYSIS: Loop %do.body: max backedge-taken count is 10000 -; CHECK-ANALYSIS: Loop %do.body: Predicated backedge-taken count is 10000 -entry: - br label %do.body - -do.body: ; preds = %do.body, %entry - %start.0 = phi i32 [ 0, %entry ], [ %inc.start.0, %do.body ] - %cmp = icmp slt i32 %start.0, 10000 - %inc = zext i1 %cmp to i32 - %inc.start.0 = add nsw i32 %start.0, %inc - br i1 %cmp, label %do.body, label %do.end - -do.end: ; preds = %do.body - ret i32 0 -}