[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner sabre at nondot.org
Wed Nov 8 11:42:42 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.539 -> 1.540
---
Log message:

reenable factoring of GEP expressions, being more precise about the
case that it bad to do.


---
Diffs of the changes:  (+10 -5)

 InstructionCombining.cpp |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.539 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.540
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.539	Wed Nov  8 13:29:23 2006
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Wed Nov  8 13:42:28 2006
@@ -6788,12 +6788,17 @@
     if (I->getOperand(1) != RHSVal) RHSVal = 0;
   }
   
-  // Otherwise, this is safe and profitable to transform.  Create up to two phi
-  // nodes.
-  PHINode *NewLHS = 0, *NewRHS = 0;
+  // Otherwise, this is safe to transform, determine if it is profitable.
+
+  // If this is a GEP, and if the index (not the pointer) needs a PHI, bail out.
+  // Indexes are often folded into load/store instructions, so we don't want to
+  // hide them behind a phi.
+  if (isa<GetElementPtrInst>(FirstInst) && RHSVal == 0)
+    return 0;
+  
   Value *InLHS = FirstInst->getOperand(0);
   Value *InRHS = FirstInst->getOperand(1);
-  
+  PHINode *NewLHS = 0, *NewRHS = 0;
   if (LHSVal == 0) {
     NewLHS = new PHINode(LHSType, FirstInst->getOperand(0)->getName()+".pn");
     NewLHS->reserveOperandSpace(PN.getNumOperands()/2);
@@ -6875,7 +6880,7 @@
         !isSafeToSinkLoad(LI))
       return 0;
   } else if (isa<GetElementPtrInst>(FirstInst)) {
-    if (0 && FirstInst->getNumOperands() == 2)
+    if (FirstInst->getNumOperands() == 2)
       return FoldPHIArgBinOpIntoPHI(PN);
     // Can't handle general GEPs yet.
     return 0;






More information about the llvm-commits mailing list