diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2011-07-11 03:43:47 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2011-07-11 03:43:47 +0000 |
commit | b5a12dd12fa3cd1026e9058a53089c29fb97f2fd (patch) | |
tree | a309f392d7a4c1a8635d31150489e47a55d4ee74 /lib/Transforms/InstCombine/InstructionCombining.cpp | |
parent | f75ae4c977b8877bb8988109dc081d512874fb37 (diff) |
Don't duplicate the work done by a gep into a "bitcast" if the gep has
more than one use.
Fixes PR10322.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134883 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstructionCombining.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 92c10f5546..278016c6ec 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -785,6 +785,14 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // getelementptr instructions into a single instruction. // if (GEPOperator *Src = dyn_cast<GEPOperator>(PtrOp)) { + + // If this GEP has only 0 indices, it is the same pointer as + // Src. If Src is not a trivial GEP too, don't combine + // the indices. + if (GEP.hasAllZeroIndices() && !Src->hasAllZeroIndices() && + !Src->hasOneUse()) + return 0; + // Note that if our source is a gep chain itself that we wait for that // chain to be resolved before we perform this transformation. This // avoids us creating a TON of code in some cases. |