aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-11-27 17:55:46 +0000
committerChris Lattner <sabre@nondot.org>2004-11-27 17:55:46 +0000
commit646641e02ccf513f76fa84d7cc3edaa9f99f2ab4 (patch)
tree3dc2abd3d7ff508cce21373de1989c9c0c364f1f
parentef1ef8272baa77ccf8a4f3f8077d29beee9a1a79 (diff)
Implement Regression/Transforms/InstCombine/getelementptr_cast.ll, which
occurs many times in crafty git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18273 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index b279d9201a..4acbc14090 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -3783,6 +3783,21 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
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());
+ }
}
}
}