summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-10-05 14:17:01 +0000
committerDuncan Sands <baldrick@free.fr>2011-10-05 14:17:01 +0000
commite90dd0587e5949aacfdb042cff1de24d0b6a104e (patch)
tree6bc4c1bf3e601638bedee12dcb612c98e0c8c040 /llvm/lib
parent9ebdf46b5a428cab0969065a89a0db9a1ec59c15 (diff)
downloadbcm5719-llvm-e90dd0587e5949aacfdb042cff1de24d0b6a104e.tar.gz
bcm5719-llvm-e90dd0587e5949aacfdb042cff1de24d0b6a104e.zip
Generalize GVN's conditional propagation logic slightly:
it's OK for the false/true destination to have multiple predecessors as long as the extra ones are dominated by the branch destination. llvm-svn: 141176
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/GVN.cpp33
1 files changed, 29 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index f0f16d84371..0ad6a8faa4c 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -1921,14 +1921,39 @@ bool GVN::processInstruction(Instruction *I) {
BasicBlock *TrueSucc = BI->getSuccessor(0);
BasicBlock *FalseSucc = BI->getSuccessor(1);
-
- if (TrueSucc->getSinglePredecessor())
+ BasicBlock *Parent = BI->getParent();
+
+ // If the true and false branches are to the same basic block then the
+ // branch gives no information about the condition. Eliminating this
+ // here simplifies the rest of the logic.
+ if (TrueSucc == FalseSucc)
+ return false;
+
+ // If the true block can be reached without executing the true edge then we
+ // can't say anything about the value of the condition there.
+ for (pred_iterator PI = pred_begin(TrueSucc), PE = pred_end(TrueSucc);
+ PI != PE; ++PI)
+ if (*PI != Parent && !DT->dominates(TrueSucc, *PI)) {
+ TrueSucc = 0;
+ break;
+ }
+
+ // If the false block can be reached without executing the false edge then
+ // we can't say anything about the value of the condition there.
+ for (pred_iterator PI = pred_begin(FalseSucc), PE = pred_end(FalseSucc);
+ PI != PE; ++PI)
+ if (*PI != Parent && !DT->dominates(FalseSucc, *PI)) {
+ FalseSucc = 0;
+ break;
+ }
+
+ if (TrueSucc)
addToLeaderTable(CondVN,
ConstantInt::getTrue(TrueSucc->getContext()),
TrueSucc);
- if (FalseSucc->getSinglePredecessor())
+ if (FalseSucc)
addToLeaderTable(CondVN,
- ConstantInt::getFalse(TrueSucc->getContext()),
+ ConstantInt::getFalse(FalseSucc->getContext()),
FalseSucc);
return false;
OpenPOWER on IntegriCloud