[llvm-branch-commits] [llvm] f1d648b - [GVN] Use m_LogicalAnd/Or to propagate equality from branch conditions

Juneyoung Lee via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sun Dec 27 12:32:53 PST 2020


Author: Juneyoung Lee
Date: 2020-12-28T05:28:38+09:00
New Revision: f1d648b973d32ab0e70ef20efb0f146240e50f58

URL: https://github.com/llvm/llvm-project/commit/f1d648b973d32ab0e70ef20efb0f146240e50f58
DIFF: https://github.com/llvm/llvm-project/commit/f1d648b973d32ab0e70ef20efb0f146240e50f58.diff

LOG: [GVN] Use m_LogicalAnd/Or to propagate equality from branch conditions

This patch makes GVN recognize `select c1, c2, false` as well as `select c1, true, c2`
branch condition and propagate equality from these.

See llvm.org/pr48353, D93065

Differential Revision: https://reviews.llvm.org/D93841

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/GVN.cpp
    llvm/test/Transforms/GVN/condprop.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index 32b38fd97f31..5d37eb73f9b1 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2087,8 +2087,8 @@ bool GVN::propagateEquality(Value *LHS, Value *RHS, const BasicBlockEdge &Root,
     // If "A && B" is known true then both A and B are known true.  If "A || B"
     // is known false then both A and B are known false.
     Value *A, *B;
-    if ((isKnownTrue && match(LHS, m_And(m_Value(A), m_Value(B)))) ||
-        (isKnownFalse && match(LHS, m_Or(m_Value(A), m_Value(B))))) {
+    if ((isKnownTrue && match(LHS, m_LogicalAnd(m_Value(A), m_Value(B)))) ||
+        (isKnownFalse && match(LHS, m_LogicalOr(m_Value(A), m_Value(B))))) {
       Worklist.push_back(std::make_pair(A, RHS));
       Worklist.push_back(std::make_pair(B, RHS));
       continue;

diff  --git a/llvm/test/Transforms/GVN/condprop.ll b/llvm/test/Transforms/GVN/condprop.ll
index c2b2c9eeaeb0..bb7befce9e82 100644
--- a/llvm/test/Transforms/GVN/condprop.ll
+++ b/llvm/test/Transforms/GVN/condprop.ll
@@ -87,13 +87,13 @@ define void @test3_select(i32 %x, i32 %y) {
   br i1 %z, label %both_zero, label %nope
 both_zero:
   call void @foo(i1 %xz)
-; CHECK: call void @foo(i1 %xz)
+; CHECK: call void @foo(i1 true)
   call void @foo(i1 %yz)
-; CHECK: call void @foo(i1 %yz)
+; CHECK: call void @foo(i1 true)
   call void @bar(i32 %x)
-; CHECK: call void @bar(i32 %x)
+; CHECK: call void @bar(i32 0)
   call void @bar(i32 %y)
-; CHECK: call void @bar(i32 %y)
+; CHECK: call void @bar(i32 0)
   ret void
 nope:
   call void @foo(i1 %z)
@@ -131,13 +131,13 @@ define void @test3_or_select(i32 %x, i32 %y) {
   br i1 %z, label %nope, label %both_zero
 both_zero:
   call void @foo(i1 %xz)
-; CHECK: call void @foo(i1 %xz)
+; CHECK: call void @foo(i1 false)
   call void @foo(i1 %yz)
-; CHECK: call void @foo(i1 %yz)
+; CHECK: call void @foo(i1 false)
   call void @bar(i32 %x)
-; CHECK: call void @bar(i32 %x)
+; CHECK: call void @bar(i32 0)
   call void @bar(i32 %y)
-; CHECK: call void @bar(i32 %y)
+; CHECK: call void @bar(i32 0)
   ret void
 nope:
   call void @foo(i1 %z)


        


More information about the llvm-branch-commits mailing list