[llvm-commits] CVS: llvm/lib/Transforms/Scalar/CondPropagate.cpp IndVarSimplify.cpp LoopStrengthReduce.cpp Reassociate.cpp

Reid Spencer reid at x10sys.com
Thu Mar 1 16:29:22 PST 2007



Changes in directory llvm/lib/Transforms/Scalar:

CondPropagate.cpp updated: 1.17 -> 1.18
IndVarSimplify.cpp updated: 1.110 -> 1.111
LoopStrengthReduce.cpp updated: 1.109 -> 1.110
Reassociate.cpp updated: 1.77 -> 1.78
---
Log message:

Prefer non-virtual calls to ConstantInt::isZero over virtual calls to 
Constant::isNullValue() in situations where it is possible.


---
Diffs of the changes:  (+29 -25)

 CondPropagate.cpp      |    2 +-
 IndVarSimplify.cpp     |    6 +++---
 LoopStrengthReduce.cpp |   38 +++++++++++++++++++++-----------------
 Reassociate.cpp        |    8 ++++----
 4 files changed, 29 insertions(+), 25 deletions(-)


Index: llvm/lib/Transforms/Scalar/CondPropagate.cpp
diff -u llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.17 llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.18
--- llvm/lib/Transforms/Scalar/CondPropagate.cpp:1.17	Thu Mar  1 15:54:37 2007
+++ llvm/lib/Transforms/Scalar/CondPropagate.cpp	Thu Mar  1 18:28:52 2007
@@ -139,7 +139,7 @@
       // ultimate destination.
       bool PHIGone = PN->getNumIncomingValues() == 2;
       RevectorBlockTo(PN->getIncomingBlock(i-1),
-                      BI->getSuccessor(CB->isNullValue()));
+                      BI->getSuccessor(CB->isZero()));
       ++NumBrThread;
 
       // If there were two predecessors before this simplification, the PHI node


Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.110 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.111
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.110	Sat Feb 10 19:23:03 2007
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp	Thu Mar  1 18:28:52 2007
@@ -178,9 +178,9 @@
               Constant *NCE = ConstantExpr::getGetElementPtr(CE->getOperand(0),
                                                              &CEIdxs[0],
                                                              CEIdxs.size());
-              GetElementPtrInst *NGEPI =
-                new GetElementPtrInst(NCE, Constant::getNullValue(Type::Int32Ty),
-                                      NewAdd, GEPI->getName(), GEPI);
+              GetElementPtrInst *NGEPI = new GetElementPtrInst(
+                  NCE, Constant::getNullValue(Type::Int32Ty), NewAdd, 
+                  GEPI->getName(), GEPI);
               GEPI->replaceAllUsesWith(NGEPI);
               GEPI->eraseFromParent();
               GEPI = NGEPI;


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.109 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.110
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.109	Sat Feb 10 13:55:17 2007
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp	Thu Mar  1 18:28:52 2007
@@ -540,7 +540,7 @@
   
   // If there is no immediate value, skip the next part.
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Imm))
-    if (SC->getValue()->isNullValue())
+    if (SC->getValue()->isZero())
       return Rewriter.expandCodeFor(NewBase, BaseInsertPt,
                                     OperandValToReplace->getType());
 
@@ -779,7 +779,7 @@
       SeparateSubExprs(SubExprs, SARE->getOperand(0));
     }
   } else if (!isa<SCEVConstant>(Expr) ||
-             !cast<SCEVConstant>(Expr)->getValue()->isNullValue()) {
+             !cast<SCEVConstant>(Expr)->getValue()->isZero()) {
     // Do not add zero.
     SubExprs.push_back(Expr);
   }
@@ -869,7 +869,7 @@
 ///
 static bool isZero(SCEVHandle &V) {
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
-    return SC->getValue()->getZExtValue() == 0;
+    return SC->getValue()->isZero();
   return false;
 }
 
@@ -883,17 +883,18 @@
   if (!TLI) return 0;
 
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) {
-    int64_t SInt = SC->getValue()->getSExtValue();
-    if (SInt == 1) return 0;
+    const APInt &SInt = SC->getValue()->getValue();
+    if (SInt == 1) 
+      return 0;
 
     for (TargetLowering::legal_am_scale_iterator
            I = TLI->legal_am_scale_begin(), E = TLI->legal_am_scale_end();
          I != E; ++I) {
-      unsigned Scale = *I;
-      if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0)
+      APInt Scale(SInt.getBitWidth(), *I);
+      if (SInt.abs().ult(Scale) || SInt.srem(Scale) != 0)
         continue;
       std::map<SCEVHandle, IVsOfOneStride>::iterator SI =
-        IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy));
+        IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt.sdiv(Scale)));
       if (SI == IVsByStride.end())
         continue;
       for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(),
@@ -902,7 +903,7 @@
         // Only reuse previous IV if it would not require a type conversion.
         if (isZero(II->Base) && II->Base->getType() == Ty) {
           IV = *II;
-          return Scale;
+          return Scale.getZExtValue();
         }
     }
   }
@@ -1148,14 +1149,14 @@
         // are reusing an IV, it has not been used to initialize the PHI node.
         // Add it to the expression used to rewrite the uses.
         if (!isa<ConstantInt>(CommonBaseV) ||
-            !cast<ConstantInt>(CommonBaseV)->isNullValue())
+            !cast<ConstantInt>(CommonBaseV)->isZero())
           RewriteExpr = SCEVAddExpr::get(RewriteExpr,
                                          SCEVUnknown::get(CommonBaseV));
       }
 
       // Now that we know what we need to do, insert code before User for the
       // immediate and any loop-variant expressions.
-      if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isNullValue())
+      if (!isa<ConstantInt>(BaseV) || !cast<ConstantInt>(BaseV)->isZero())
         // Add BaseV to the PHI value if needed.
         RewriteExpr = SCEVAddExpr::get(RewriteExpr, SCEVUnknown::get(BaseV));
 
@@ -1257,14 +1258,17 @@
       SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS);
       SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);
       if (LHSC && RHSC) {
-        int64_t  LV = LHSC->getValue()->getSExtValue();
-        int64_t  RV = RHSC->getValue()->getSExtValue();
-        uint64_t ALV = (LV < 0) ? -LV : LV;
-        uint64_t ARV = (RV < 0) ? -RV : RV;
+        APInt LV(LHSC->getValue()->getValue());
+        APInt RV(RHSC->getValue()->getValue());
+        uint32_t MaxWidth = std::max(LV.getBitWidth(), RV.getBitWidth());
+        LV.sextOrTrunc(MaxWidth);
+        RV.sextOrTrunc(MaxWidth);
+        APInt ALV(LV.abs());
+        APInt ARV(RV.abs());
         if (ALV == ARV)
-          return LV > RV;
+          return LV.sgt(RV);
         else
-          return ALV < ARV;
+          return ALV.ult(ARV);
       }
       return (LHSC && !RHSC);
     }


Index: llvm/lib/Transforms/Scalar/Reassociate.cpp
diff -u llvm/lib/Transforms/Scalar/Reassociate.cpp:1.77 llvm/lib/Transforms/Scalar/Reassociate.cpp:1.78
--- llvm/lib/Transforms/Scalar/Reassociate.cpp:1.77	Thu Mar  1 15:51:23 2007
+++ llvm/lib/Transforms/Scalar/Reassociate.cpp	Thu Mar  1 18:28:52 2007
@@ -536,7 +536,7 @@
     switch (Opcode) {
     default: break;
     case Instruction::And:
-      if (CstVal->isNullValue()) {           // ... & 0 -> 0
+      if (CstVal->isZero()) {                // ... & 0 -> 0
         ++NumAnnihil;
         return CstVal;
       } else if (CstVal->isAllOnesValue()) { // ... & -1 -> ...
@@ -544,10 +544,10 @@
       }
       break;
     case Instruction::Mul:
-      if (CstVal->isNullValue()) {           // ... * 0 -> 0
+      if (CstVal->isZero()) {                // ... * 0 -> 0
         ++NumAnnihil;
         return CstVal;
-      } else if (cast<ConstantInt>(CstVal)->isUnitValue()) {
+      } else if (cast<ConstantInt>(CstVal)->isOne()) {
         Ops.pop_back();                      // ... * 1 -> ...
       }
       break;
@@ -559,7 +559,7 @@
       // FALLTHROUGH!
     case Instruction::Add:
     case Instruction::Xor:
-      if (CstVal->isNullValue())             // ... [|^+] 0 -> ...
+      if (CstVal->isZero())                  // ... [|^+] 0 -> ...
         Ops.pop_back();
       break;
     }






More information about the llvm-commits mailing list