[llvm-commits] [llvm] r141176 - in /llvm/trunk: lib/Transforms/Scalar/GVN.cpp test/Transforms/GVN/condprop.ll
Duncan Sands
baldrick at free.fr
Wed Oct 5 07:17:05 PDT 2011
Author: baldrick
Date: Wed Oct 5 09:17:01 2011
New Revision: 141176
URL: http://llvm.org/viewvc/llvm-project?rev=141176&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
llvm/trunk/test/Transforms/GVN/condprop.ll
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=141176&r1=141175&r2=141176&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Wed Oct 5 09:17:01 2011
@@ -1921,14 +1921,39 @@
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;
Modified: llvm/trunk/test/Transforms/GVN/condprop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/condprop.ll?rev=141176&r1=141175&r2=141176&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/condprop.ll (original)
+++ llvm/trunk/test/Transforms/GVN/condprop.ll Wed Oct 5 09:17:01 2011
@@ -52,4 +52,24 @@
return: ; preds = %bb8
ret i32 %.0
-}
\ No newline at end of file
+}
+
+declare void @ext(i1)
+
+; CHECK: @bar
+define void @bar(i1 %x, i1 %y) {
+ %z = or i1 %x, %y
+ br i1 %z, label %true, label %false
+true:
+; CHECK: true:
+ %z2 = or i1 %x, %y
+ call void @ext(i1 %z2)
+; CHECK: call void @ext(i1 true)
+ br label %true
+false:
+; CHECK: false:
+ %z3 = or i1 %x, %y
+ call void @ext(i1 %z3)
+; CHECK: call void @ext(i1 false)
+ br label %false
+}
More information about the llvm-commits
mailing list