[llvm-commits] [llvm] r65347 - in /llvm/trunk: lib/Transforms/Scalar/IndVarSimplify.cpp test/Transforms/IndVarSimplify/preserve-signed-wrap.ll test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll test/Transforms/IndVarSimplify/signed-trip-count.ll

Dan Gohman gohman at apple.com
Mon Feb 23 15:20:36 PST 2009


Author: djg
Date: Mon Feb 23 17:20:35 2009
New Revision: 65347

URL: http://llvm.org/viewvc/llvm-project?rev=65347&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
    llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
    llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll
    llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=65347&r1=65346&r2=65347&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Feb 23 17:20:35 2009
@@ -97,8 +97,7 @@
                                    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 @@
                                    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 @@
     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 @@
     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 @@
 /// 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 @@
                                         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 @@
   // 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 @@
   // 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 @@
         // 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

Modified: llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll?rev=65347&r1=65346&r2=65347&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll Mon Feb 23 17:20:35 2009
@@ -1,6 +1,5 @@
 ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
-; RUN: grep sext %t | count 2
-; RUN: grep { = sext i32 %n to i64} %t
+; RUN: grep sext %t | count 1
 ; RUN: grep phi %t | count 1
 ; RUN: grep {phi i64} %t
 

Modified: llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll?rev=65347&r1=65346&r2=65347&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/promote-iv-to-eliminate-casts.ll Mon Feb 23 17:20:35 2009
@@ -1,7 +1,5 @@
 ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
-; RUN: grep sext %t | count 2
-; RUN: grep { = sext i16 %N to i64} %t
-; RUN: grep { = sext i32 %count to i64} %t
+; RUN: not grep sext %t
 
 define i64 @test(i64* nocapture %first, i32 %count) nounwind readonly {
 entry:

Modified: llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll?rev=65347&r1=65346&r2=65347&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/signed-trip-count.ll Mon Feb 23 17:20:35 2009
@@ -1,7 +1,6 @@
 ; RUN: llvm-as < %s | opt -indvars | llvm-dis > %t
-; RUN: grep { = sext i32 %n} %t
+; RUN: not grep sext %t
 ; RUN: grep phi %t | count 1
-; RUN: not grep zext %t
 
 define void @foo(i64* nocapture %x, i32 %n) nounwind {
 entry:





More information about the llvm-commits mailing list