summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-16 05:28:59 +0000
committerChris Lattner <sabre@nondot.org>2011-01-16 05:28:59 +0000
commitd55581ded8454dc023acc4020497d403e191dff7 (patch)
treeafefe709bb96bc4903b52c75094b741fd77a85a9 /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
parent572756ac1109b3aea5f57ef354827e7ea4b5b5ec (diff)
downloadbcm5719-llvm-d55581ded8454dc023acc4020497d403e191dff7.tar.gz
bcm5719-llvm-d55581ded8454dc023acc4020497d403e191dff7.zip
enhance FoldOpIntoPhi in instcombine to try harder when a phi has
multiple uses. In some cases, all the uses are the same operation, so instcombine can go ahead and promote the phi. In the testcase this pushes an add out of the loop. llvm-svn: 123568
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6d05466b9be..23e76ee499f 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -519,9 +519,17 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
return 0;
// We normally only transform phis with a single use, unless we're trying
- // hard to make jump threading happen.
- if (!PN->hasOneUse())
- return 0;
+ // hard to make jump threading happen. However, if a PHI has multiple uses
+ // and they are all the same operation, we can fold *all* of the uses into the
+ // PHI.
+ if (!PN->hasOneUse()) {
+ // Walk the use list for the instruction, comparing them to I.
+ for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end();
+ UI != E; ++UI)
+ if (!I.isIdenticalTo(cast<Instruction>(*UI)))
+ return 0;
+ // Otherwise, we can replace *all* users with the new PHI we form.
+ }
// Check to see if all of the operands of the PHI are simple constants
// (constantint/constantfp/undef). If there is one non-constant value,
@@ -628,6 +636,14 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
NewPN->addIncoming(InV, PN->getIncomingBlock(i));
}
}
+
+ for (Value::use_iterator UI = PN->use_begin(), E = PN->use_end();
+ UI != E; ) {
+ Instruction *User = cast<Instruction>(*UI++);
+ if (User == &I) continue;
+ ReplaceInstUsesWith(*User, NewPN);
+ EraseInstFromFunction(*User);
+ }
return ReplaceInstUsesWith(I, NewPN);
}
OpenPOWER on IntegriCloud