diff options
| author | Chris Lattner <sabre@nondot.org> | 2004-11-27 17:55:46 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2004-11-27 17:55:46 +0000 |
| commit | 14f3cdc2278d244707df6b884c8f41b3a0647146 (patch) | |
| tree | 8b37690544cfdb060d70f27fc0d50a96cb473a1c /llvm/lib | |
| parent | 7c4026ae24640b9dc3a91a4e618915948daf104b (diff) | |
| download | bcm5719-llvm-14f3cdc2278d244707df6b884c8f41b3a0647146.tar.gz bcm5719-llvm-14f3cdc2278d244707df6b884c8f41b3a0647146.zip | |
Implement Regression/Transforms/InstCombine/getelementptr_cast.ll, which
occurs many times in crafty
llvm-svn: 18273
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index b279d9201ae..4acbc140900 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/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()); + } } } } |

