aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-11-04 16:43:32 +0000
committerChris Lattner <sabre@nondot.org>2002-11-04 16:43:32 +0000
commit0188534cd1db5118a3dc0570be67c08dfcf957b2 (patch)
tree26d63e116118d22ee958b067a29662a45929bc64 /lib
parenta3c4ba427b6f1ea2abe62e33695a032112d8d3b8 (diff)
Instcombine this away:
%A = getelementptr [4 x int]* %M, long 0, long 0 %B = getelementptr int* %A, long 2 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4536 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index df3a611ba2..e540310f6b 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -681,11 +681,17 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
*cast<Constant>(GEP.getOperand(1));
assert(Indices[0] != 0 && "Constant folding of uint's failed!?");
- } else if (*GEP.idx_begin() == ConstantUInt::getNullValue(Type::LongTy) &&
+ } else if (*GEP.idx_begin() == Constant::getNullValue(Type::LongTy) &&
Src->getNumOperands() != 1) {
// Otherwise we can do the fold if the first index of the GEP is a zero
Indices.insert(Indices.end(), Src->idx_begin(), Src->idx_end());
Indices.insert(Indices.end(), GEP.idx_begin()+1, GEP.idx_end());
+ } else if (Src->getOperand(Src->getNumOperands()-1) ==
+ Constant::getNullValue(Type::LongTy)) {
+ // If the src gep ends with a constant array index, merge this get into
+ // it, even if we have a non-zero array index.
+ Indices.insert(Indices.end(), Src->idx_begin(), Src->idx_end()-1);
+ Indices.insert(Indices.end(), GEP.idx_begin(), GEP.idx_end());
}
if (!Indices.empty())