summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-04-25 20:17:30 +0000
committerChris Lattner <sabre@nondot.org>2005-04-25 20:17:30 +0000
commita21bf8d1be678843d8bdf6ad5b7185b02a38b5da (patch)
tree3e75b4f7e680b3f49b906b1bf8051c31f81115f6 /llvm/lib/Transforms
parent20621b1e94f23129a562649d33aa6c8d81031e79 (diff)
downloadbcm5719-llvm-a21bf8d1be678843d8bdf6ad5b7185b02a38b5da.tar.gz
bcm5719-llvm-a21bf8d1be678843d8bdf6ad5b7185b02a38b5da.zip
implement getelementptr.ll:test10
llvm-svn: 21541
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index ad60a75f326..83d390d4aea 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2277,8 +2277,26 @@ Instruction *InstCombiner::FoldGEPSetCC(User *GEPLHS, Value *RHS,
Constant::getNullValue(Offset->getType()));
}
} else if (User *GEPRHS = dyn_castGetElementPtr(RHS)) {
- if (PtrBase != GEPRHS->getOperand(0))
+ // If the base pointers are different, but the indices are the same, just
+ // compare the base pointer.
+ if (PtrBase != GEPRHS->getOperand(0)) {
+ bool IndicesTheSame = GEPLHS->getNumOperands()==GEPRHS->getNumOperands();
+ if (IndicesTheSame)
+ for (unsigned i = 1, e = GEPLHS->getNumOperands(); i != e; ++i)
+ if (GEPLHS->getOperand(i) != GEPRHS->getOperand(i)) {
+ IndicesTheSame = false;
+ break;
+ }
+
+ // If all indices are the same, just compare the base pointers.
+ if (IndicesTheSame)
+ return new SetCondInst(Cond, GEPLHS->getOperand(0),
+ GEPRHS->getOperand(0));
+
+ // Otherwise, the base pointers are different and the indices are
+ // different, bail out.
return 0;
+ }
// If one of the GEPs has all zero indices, recurse.
bool AllZeros = true;
OpenPOWER on IntegriCloud