indvars: minor cleanup in preparation for sign/zero extend elimination.
authorAndrew Trick <atrick@apple.com>
Fri, 20 May 2011 03:37:48 +0000 (03:37 +0000)
committerAndrew Trick <atrick@apple.com>
Fri, 20 May 2011 03:37:48 +0000 (03:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131716 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/IndVarSimplify.cpp

index 99f5e7fd66b5038c9038f03e282215d727d06f23..ea38027c4dc6bfe246ad82e9bc036e026a15c0d2 100644 (file)
@@ -113,7 +113,7 @@ namespace {
     void EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand);
     void EliminateIVRemainder(BinaryOperator *Rem,
                               Value *IVOperand,
-                              bool isSigned);
+                              bool IsSigned);
     void RewriteNonIntegerIVs(Loop *L);
     const Type *WidenIVs(Loop *L, SCEVExpander &Rewriter);
 
@@ -468,9 +468,9 @@ void IndVarSimplify::SimplifyIVUsers() {
     }
 
     if (BinaryOperator *Rem = dyn_cast<BinaryOperator>(UseInst)) {
-      bool isSigned = Rem->getOpcode() == Instruction::SRem;
-      if (isSigned || Rem->getOpcode() == Instruction::URem) {
-        EliminateIVRemainder(Rem, IVOperand, isSigned);
+      bool IsSigned = Rem->getOpcode() == Instruction::SRem;
+      if (IsSigned || Rem->getOpcode() == Instruction::URem) {
+        EliminateIVRemainder(Rem, IVOperand, IsSigned);
         continue;
       }
     }
@@ -506,12 +506,13 @@ void IndVarSimplify::EliminateIVComparison(ICmpInst *ICmp, Value *IVOperand) {
     return;
 
   DEBUG(dbgs() << "INDVARS: Eliminated comparison: " << *ICmp << '\n');
+  Changed = true;
   DeadInsts.push_back(ICmp);
 }
 
 void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
                                           Value *IVOperand,
-                                          bool isSigned) {
+                                          bool IsSigned) {
   // We're only interested in the case where we know something about
   // the numerator.
   if (IVOperand != Rem->getOperand(0))
@@ -527,18 +528,18 @@ void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
   X = SE->getSCEVAtScope(X, ICmpLoop);
 
   // i % n  -->  i  if i is in [0,n).
-  if ((!isSigned || SE->isKnownNonNegative(S)) &&
-      SE->isKnownPredicate(isSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
+  if ((!IsSigned || SE->isKnownNonNegative(S)) &&
+      SE->isKnownPredicate(IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
                            S, X))
     Rem->replaceAllUsesWith(Rem->getOperand(0));
   else {
     // (i+1) % n  -->  (i+1)==n?0:(i+1)  if i is in [0,n).
     const SCEV *LessOne =
       SE->getMinusSCEV(S, SE->getConstant(S->getType(), 1));
-    if (isSigned && !SE->isKnownNonNegative(LessOne))
+    if (IsSigned && !SE->isKnownNonNegative(LessOne))
       return;
 
-    if (!SE->isKnownPredicate(isSigned ?
+    if (!SE->isKnownPredicate(IsSigned ?
                               ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
                               LessOne, X))
       return;
@@ -558,6 +559,7 @@ void IndVarSimplify::EliminateIVRemainder(BinaryOperator *Rem,
     IU->AddUsersIfInteresting(I);
 
   DEBUG(dbgs() << "INDVARS: Simplified rem: " << *Rem << '\n');
+  Changed = true;
   DeadInsts.push_back(Rem);
 }
 
@@ -624,15 +626,6 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) {
         SE->getTypeSizeInBits(LargestType))
       LargestType = SE->getEffectiveSCEVType(Ty);
   }
-  for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) {
-    NeedCannIV = true;
-    const Type *Ty =
-      SE->getEffectiveSCEVType(I->getOperandValToReplace()->getType());
-    if (!LargestType ||
-        SE->getTypeSizeInBits(Ty) >
-        SE->getTypeSizeInBits(LargestType))
-      LargestType = SE->getEffectiveSCEVType(Ty);
-  }
   if (!DisableIVRewrite) {
     for (IVUsers::const_iterator I = IU->begin(), E = IU->end(); I != E; ++I) {
       NeedCannIV = true;