[llvm-commits] CVS: llvm/lib/Analysis/ScalarEvolution.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Apr 14 17:02:01 PDT 2004


Changes in directory llvm/lib/Analysis:

ScalarEvolution.cpp updated: 1.8 -> 1.9

---
Log message:

Implement a FIXME: if we're going to insert a cast, we might as well only
insert it once!


---
Diffs of the changes:  (+15 -1)

Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.8 llvm/lib/Analysis/ScalarEvolution.cpp:1.9
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.8	Wed Apr 14 16:11:25 2004
+++ llvm/lib/Analysis/ScalarEvolution.cpp	Wed Apr 14 17:01:22 2004
@@ -2484,7 +2484,21 @@
   if (Constant *C = dyn_cast<Constant>(V))
     return ConstantExpr::getCast(C, Ty);
   else if (Instruction *I = dyn_cast<Instruction>(V)) {
-    // FIXME: check to see if there is already a cast!
+    // Check to see if there is already a cast.  If there is, use it.
+    for (Value::use_iterator UI = I->use_begin(), E = I->use_end(); 
+         UI != E; ++UI) {
+      if ((*UI)->getType() == Ty)
+        if (CastInst *CI = dyn_cast<CastInst>(cast<Instruction>(*UI))) {
+          BasicBlock::iterator It = I; ++It;
+          if (It != BasicBlock::iterator(CI)) {
+            // Splice the cast immediately after the operand in question.
+            I->getParent()->getInstList().splice(It,
+                                                 CI->getParent()->getInstList(),
+                                                 CI);
+          }
+          return CI;
+        }
+    }
     BasicBlock::iterator IP = I; ++IP;
     if (InvokeInst *II = dyn_cast<InvokeInst>(I))
       IP = II->getNormalDest()->begin();





More information about the llvm-commits mailing list