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

Chris Lattner lattner at cs.uiuc.edu
Sat Nov 27 09:55:58 PST 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.286 -> 1.287
---
Log message:

Implement Regression/Transforms/InstCombine/getelementptr_cast.ll, which
occurs many times in crafty


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

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.286 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.287
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.286	Thu Nov 18 15:41:39 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sat Nov 27 11:55:46 2004
@@ -3783,6 +3783,21 @@
                 GEP.setOperand(0, X);
                 return &GEP;
               }
+      } else if (GEP.getNumOperands() == 2) {
+        // Transform things like:
+        // %t = getelementptr ubyte* cast ([2 x sbyte]* %str to ubyte*), uint %V
+        // into:  %t1 = getelementptr [2 x sbyte*]* %str, int 0, uint %V; cast
+        Constant *X = CE->getOperand(0);
+        const Type *SrcElTy = cast<PointerType>(X->getType())->getElementType();
+        const Type *ResElTy =cast<PointerType>(CE->getType())->getElementType();
+        if (isa<ArrayType>(SrcElTy) &&
+            TD->getTypeSize(cast<ArrayType>(SrcElTy)->getElementType()) == 
+            TD->getTypeSize(ResElTy)) {
+          Value *V = InsertNewInstBefore(
+                 new GetElementPtrInst(X, Constant::getNullValue(Type::IntTy),
+                                       GEP.getOperand(1), GEP.getName()), GEP);
+          return new CastInst(V, GEP.getType());
+        }
       }
     }
   }






More information about the llvm-commits mailing list