[llvm-commits] [llvm] r100273 - /llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp

Chris Lattner sabre at nondot.org
Fri Apr 2 23:11:07 PDT 2010


Author: lattner
Date: Sat Apr  3 01:11:07 2010
New Revision: 100273

URL: http://llvm.org/viewvc/llvm-project?rev=100273&view=rev
Log:
rename stuff improve comment grammar.

Modified:
    llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=100273&r1=100272&r2=100273&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Sat Apr  3 01:11:07 2010
@@ -625,8 +625,8 @@
 
 /// Return true if it is OK to use SIToFPInst for an induction variable
 /// with given initial and exit values.
-static bool useSIToFPInst(ConstantFP *InitV, ConstantFP *ExitV,
-                          uint64_t intIV, uint64_t intEV) {
+static bool CanUseSIToFP(ConstantFP *InitV, ConstantFP *ExitV,
+                         uint64_t intIV, uint64_t intEV) {
 
   if (InitV->getValueAPF().isNegative() || ExitV->getValueAPF().isNegative())
     return true;
@@ -698,24 +698,25 @@
 
   // Find exit condition, which is an fcmp.  If it doesn't exist, or if it isn't
   // only used by a branch, we can't transform it.
-  FCmpInst *EC = dyn_cast<FCmpInst>(U1);
-  if (!EC)
-    EC = dyn_cast<FCmpInst>(U2);
-  if (EC == 0 || !EC->hasOneUse() || !isa<BranchInst>(EC->use_back()))
+  FCmpInst *Compare = dyn_cast<FCmpInst>(U1);
+  if (!Compare)
+    Compare = dyn_cast<FCmpInst>(U2);
+  if (Compare == 0 || !Compare->hasOneUse() ||
+      !isa<BranchInst>(Compare->use_back()))
     return;
   
-  BranchInst *TheBr = cast<BranchInst>(EC->use_back());
+  BranchInst *TheBr = cast<BranchInst>(Compare->use_back());
 
   // If it isn't a comparison with an integer-as-fp (the exit value), we can't
   // transform it.
-  ConstantFP *ExitValueVal = dyn_cast<ConstantFP>(EC->getOperand(1));
+  ConstantFP *ExitValueVal = dyn_cast<ConstantFP>(Compare->getOperand(1));
   uint64_t ExitValue;
   if (ExitValueVal == 0 || !convertToInt(ExitValueVal->getValueAPF(),ExitValue))
     return;
 
   // Find new predicate for integer comparison.
   CmpInst::Predicate NewPred = CmpInst::BAD_ICMP_PREDICATE;
-  switch (EC->getPredicate()) {
+  switch (Compare->getPredicate()) {
   default: return;  // Unknown comparison.
   case CmpInst::FCMP_OEQ:
   case CmpInst::FCMP_UEQ: NewPred = CmpInst::ICMP_EQ; break;
@@ -731,7 +732,7 @@
 
   const IntegerType *Int32Ty = Type::getInt32Ty(PH->getContext());
   
-  // Insert new integer induction variable.
+  // Insert new i32 integer induction variable.
   PHINode *NewPHI = PHINode::Create(Int32Ty, PH->getName()+".int", PH);
   NewPHI->addIncoming(ConstantInt::get(Int32Ty, InitValue),
                       PH->getIncomingBlock(IncomingEdge));
@@ -741,23 +742,21 @@
                               Incr->getName()+".int", Incr);
   NewPHI->addIncoming(NewAdd, PH->getIncomingBlock(BackEdge));
 
-  // The back edge is edge 1 of newPHI, whatever it may have been in the
-  // original PHI.
-  ConstantInt *NewEV = ConstantInt::get(Int32Ty, ExitValue);
-  
-  ICmpInst *NewCompare = new ICmpInst(TheBr, NewPred, NewAdd, NewEV,
-                                      EC->getName());
+  ICmpInst *NewCompare = new ICmpInst(TheBr, NewPred, NewAdd,
+                                      ConstantInt::get(Int32Ty, ExitValue),
+                                      Compare->getName());
 
   // In the following deletions, PH may become dead and may be deleted.
   // Use a WeakVH to observe whether this happens.
   WeakVH WeakPH = PH;
 
-  // Delete old, floating point, exit comparison instruction.
-  NewCompare->takeName(EC);
-  EC->replaceAllUsesWith(NewCompare);
-  RecursivelyDeleteTriviallyDeadInstructions(EC);
+  // Delete the old floating point exit comparison.  The branch starts using the
+  // new comparison.
+  NewCompare->takeName(Compare);
+  Compare->replaceAllUsesWith(NewCompare);
+  RecursivelyDeleteTriviallyDeadInstructions(Compare);
 
-  // Delete old, floating point, increment instruction.
+  // Delete the old floating point increment.
   Incr->replaceAllUsesWith(UndefValue::get(Incr->getType()));
   RecursivelyDeleteTriviallyDeadInstructions(Incr);
 
@@ -765,7 +764,7 @@
   // Give SIToFPInst preference over UIToFPInst because it is faster on
   // platforms that are widely used.
   if (WeakPH && !PH->use_empty()) {
-    if (useSIToFPInst(InitValueVal, ExitValueVal, InitValue, ExitValue)) {
+    if (CanUseSIToFP(InitValueVal, ExitValueVal, InitValue, ExitValue)) {
       SIToFPInst *Conv = new SIToFPInst(NewPHI, PH->getType(), "indvar.conv",
                                         PH->getParent()->getFirstNonPHI());
       PH->replaceAllUsesWith(Conv);





More information about the llvm-commits mailing list