From f1d648b973d32ab0e70ef20efb0f146240e50f58 Mon Sep 17 00:00:00 2001 From: Juneyoung Lee Date: Mon, 28 Dec 2020 03:46:28 +0900 Subject: [PATCH] [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 --- llvm/lib/Transforms/Scalar/GVN.cpp | 4 ++-- llvm/test/Transforms/GVN/condprop.ll | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp index 32b38fd..5d37eb7 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 c2b2c9e..bb7befc 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) -- 2.7.4