summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSilviu Baranga <silviu.baranga@arm.com>2015-10-26 10:25:05 +0000
committerSilviu Baranga <silviu.baranga@arm.com>2015-10-26 10:25:05 +0000
commitb892e35520280a64b13e364904a6f7776c873999 (patch)
treebbec27113c4ce81e6573bd4a69c0fd9ba55c806c /llvm/lib/Transforms
parent72222f5dcafbf19905908197793732fe07458595 (diff)
downloadbcm5719-llvm-b892e35520280a64b13e364904a6f7776c873999.tar.gz
bcm5719-llvm-b892e35520280a64b13e364904a6f7776c873999.zip
[InstCombine] Teach instcombine not to create extra PHI nodes when folding GEPs
Summary: InstCombine tries to transform GEP(PHI(GEP1, GEP2, ..)) into GEP(GEP(PHI(...)) when possible. However, this may leave the old PHI node around. Even if we do end up folding the GEPs, having an extra PHI node might not be beneficial. This change makes the transformation more conservative. We now only do this if the PHI has only one use, and can therefore be removed after the transformation. Reviewers: jmolloy, majnemer Subscribers: mcrosier, mssimpso, llvm-commits Differential Revision: http://reviews.llvm.org/D13887 llvm-svn: 251281
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 69a2661f031..b51ec291f91 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1453,8 +1453,13 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
}
}
- GetElementPtrInst *NewGEP = cast<GetElementPtrInst>(Op1->clone());
+ // If not all GEPs are identical we'll have to create a new PHI node.
+ // Check that the old PHI node has only one use so that it will get
+ // removed.
+ if (DI != -1 && !PN->hasOneUse())
+ return nullptr;
+ GetElementPtrInst *NewGEP = cast<GetElementPtrInst>(Op1->clone());
if (DI == -1) {
// All the GEPs feeding the PHI are identical. Clone one down into our
// BB so that it can be merged with the current GEP.
OpenPOWER on IntegriCloud