diff options
author | Dan Gohman <gohman@apple.com> | 2009-02-23 23:20:35 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-02-23 23:20:35 +0000 |
commit | 15cab2817b8f63fec0148609278bc2c1e05abb50 (patch) | |
tree | 24003b8481aa66fad2ca12e1118566706fbf0cae /lib | |
parent | e9865945ad8286a007d8b8465703c5b242f94caa (diff) | |
download | llvm-15cab2817b8f63fec0148609278bc2c1e05abb50.tar.gz llvm-15cab2817b8f63fec0148609278bc2c1e05abb50.tar.bz2 llvm-15cab2817b8f63fec0148609278bc2c1e05abb50.tar.xz |
Back out the change in 64918 that used sign-extensions when promoting
trip counts that use signed comparisons. It's not obviously the best
approach for preserving trip count information, and at any rate there
isn't anything in the tree right now that makes use of that, so for
now always using zero-extensions is preferable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65347 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 1207dbf8e3..6b52ed7b84 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -97,8 +97,7 @@ namespace { Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, - SCEVExpander &Rewriter, - bool SignExtendTripCount); + SCEVExpander &Rewriter); void RewriteLoopExitValues(Loop *L, SCEV *IterationCount); void DeleteTriviallyDeadInstructions(SmallPtrSet<Instruction*, 16> &Insts); @@ -237,8 +236,7 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, Value *IndVar, BasicBlock *ExitingBlock, BranchInst *BI, - SCEVExpander &Rewriter, - bool SignExtendTripCount) { + SCEVExpander &Rewriter) { // If the exiting block is not the same as the backedge block, we must compare // against the preincremented value, otherwise we prefer to compare against // the post-incremented value. @@ -256,18 +254,11 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, if ((isa<SCEVConstant>(N) && !N->isZero()) || SE->isLoopGuardedByCond(L, ICmpInst::ICMP_NE, N, Zero)) { // No overflow. Cast the sum. - if (SignExtendTripCount) - IterationCount = SE->getTruncateOrSignExtend(N, IndVar->getType()); - else - IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType()); + IterationCount = SE->getTruncateOrZeroExtend(N, IndVar->getType()); } else { // Potential overflow. Cast before doing the add. - if (SignExtendTripCount) - IterationCount = SE->getTruncateOrSignExtend(IterationCount, - IndVar->getType()); - else - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, - IndVar->getType()); + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, + IndVar->getType()); IterationCount = SE->getAddExpr(IterationCount, SE->getIntegerSCEV(1, IndVar->getType())); @@ -279,12 +270,8 @@ void IndVarSimplify::LinearFunctionTestReplace(Loop *L, CmpIndVar = L->getCanonicalInductionVariableIncrement(); } else { // We have to use the preincremented value... - if (SignExtendTripCount) - IterationCount = SE->getTruncateOrSignExtend(IterationCount, - IndVar->getType()); - else - IterationCount = SE->getTruncateOrZeroExtend(IterationCount, - IndVar->getType()); + IterationCount = SE->getTruncateOrZeroExtend(IterationCount, + IndVar->getType()); CmpIndVar = IndVar; } @@ -482,9 +469,8 @@ static const Type *getEffectiveIndvarType(const PHINode *Phi) { /// whether an induction variable in the same type that starts /// at 0 would undergo signed overflow. /// -/// In addition to setting the NoSignedWrap, NoUnsignedWrap, and -/// SignExtendTripCount variables, return the PHI for this induction -/// variable. +/// In addition to setting the NoSignedWrap, and NoUnsignedWrap, +/// variables, return the PHI for this induction variable. /// /// TODO: This duplicates a fair amount of ScalarEvolution logic. /// Perhaps this can be merged with ScalarEvolution::getIterationCount @@ -494,8 +480,7 @@ static const PHINode *TestOrigIVForWrap(const Loop *L, const BranchInst *BI, const Instruction *OrigCond, bool &NoSignedWrap, - bool &NoUnsignedWrap, - bool &SignExtendTripCount) { + bool &NoUnsignedWrap) { // Verify that the loop is sane and find the exit condition. const ICmpInst *Cmp = dyn_cast<ICmpInst>(OrigCond); if (!Cmp) return 0; @@ -610,10 +595,6 @@ static const PHINode *TestOrigIVForWrap(const Loop *L, // less than some value in the same type. As such, it will never wrap. if (isSigned && !InitialVal->getValue().isMaxSignedValue()) { NoSignedWrap = true; - // If the original induction variable starts at zero or greater, - // the trip count can be considered signed. - if (InitialVal->getValue().isNonNegative()) - SignExtendTripCount = true; } else if (!isSigned && !InitialVal->getValue().isMaxValue()) NoUnsignedWrap = true; return PN; @@ -700,7 +681,6 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // using it. We can currently only handle loops with a single exit. bool NoSignedWrap = false; bool NoUnsignedWrap = false; - bool SignExtendTripCount = false; const PHINode *OrigControllingPHI = 0; if (!isa<SCEVCouldNotCompute>(IterationCount) && ExitingBlock) // Can't rewrite non-branch yet. @@ -709,16 +689,14 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { // Determine if the OrigIV will ever undergo overflow. OrigControllingPHI = TestOrigIVForWrap(L, BI, OrigCond, - NoSignedWrap, NoUnsignedWrap, - SignExtendTripCount); + NoSignedWrap, NoUnsignedWrap); // We'll be replacing the original condition, so it'll be dead. DeadInsts.insert(OrigCond); } LinearFunctionTestReplace(L, IterationCount, IndVar, - ExitingBlock, BI, Rewriter, - SignExtendTripCount); + ExitingBlock, BI, Rewriter); } // Now that we have a canonical induction variable, we can rewrite any |