diff options
| author | Wei Mi <wmi@google.com> | 2015-04-21 22:37:09 +0000 |
|---|---|---|
| committer | Wei Mi <wmi@google.com> | 2015-04-21 22:37:09 +0000 |
| commit | 6e3344ed98a3432bf59a9d9b28b7bb869ca10912 (patch) | |
| tree | 556870783df48e2aa419bbc7c3cf2f2b00c17e46 /llvm/lib/Transforms | |
| parent | 84e55fc5f23330b9aaa4cfcc1d1883c982a308df (diff) | |
| download | bcm5719-llvm-6e3344ed98a3432bf59a9d9b28b7bb869ca10912.tar.gz bcm5719-llvm-6e3344ed98a3432bf59a9d9b28b7bb869ca10912.zip | |
Limiting gep merging to fix the performance problem described in
https://llvm.org/bugs/show_bug.cgi?id=23163.
Gep merging sometimes behaves like a reverse CSE/LICM optimizations,
which has negative impact on performance. In this patch we restrict
gep merging to happen only when the indexes to be merged are both consts,
which ensures such merge is always beneficial.
The patch makes gep merging only happen in very restrictive cases.
It is possible that some analysis/optimization passes rely on the merged
geps to get better result, and we havn't notice them yet. We will be ready
to further improve it once we see the cases.
Differential Revision: http://reviews.llvm.org/D9007
llvm-svn: 235451
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 3b46156c1ab..f62941fbf64 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1467,6 +1467,11 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // normalized. if (SO1->getType() != GO1->getType()) return nullptr; + // Only do the combine when GO1 and SO1 are both constants. Only in + // this case, we are sure the cost after the merge is never more than + // that before the merge. + if (!isa<Constant>(GO1) || !isa<Constant>(SO1)) + return nullptr; Sum = Builder->CreateAdd(SO1, GO1, PtrOp->getName()+".sum"); } |

