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

Chris Lattner lattner at cs.uiuc.edu
Mon Jul 19 18:48:25 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.226 -> 1.227

---
Log message:

Implement InstCombine/GEPIdxCanon.ll


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

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.226 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.227
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.226	Mon Jul 19 19:59:32 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Jul 19 20:48:15 2004
@@ -2700,7 +2700,8 @@
       Value *Op = GEP.getOperand(i);
       if (Op->getType()->getPrimitiveSize() > TD->getPointerSize())
         if (Constant *C = dyn_cast<Constant>(Op)) {
-          GEP.setOperand(i, ConstantExpr::getCast(C, TD->getIntPtrType()));
+          GEP.setOperand(i, ConstantExpr::getCast(C,
+                                     TD->getIntPtrType()->getSignedVersion()));
           MadeChange = true;
         } else {
           Op = InsertNewInstBefore(new CastInst(Op, TD->getIntPtrType(),
@@ -2708,6 +2709,14 @@
           GEP.setOperand(i, Op);
           MadeChange = true;
         }
+
+      // If this is a constant idx, make sure to canonicalize it to be a signed
+      // operand, otherwise CSE and other optimizations are pessimized.
+      if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(Op)) {
+        GEP.setOperand(i, ConstantExpr::getCast(CUI,
+                                          CUI->getType()->getSignedVersion()));
+        MadeChange = true;
+      }
     }
   if (MadeChange) return &GEP;
 





More information about the llvm-commits mailing list