[PATCH] D93841: [GVN] Use m_LogicalAnd/Or to propagate equality from branch conditions
Juneyoung Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 27 10:49:22 PST 2020
aqjune created this revision.
aqjune added reviewers: nikic, lebedev.ri, spatel.
Herald added a subscriber: hiraditya.
aqjune requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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 <https://reviews.llvm.org/D93065>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D93841
Files:
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/condprop.ll
Index: llvm/test/Transforms/GVN/condprop.ll
===================================================================
--- llvm/test/Transforms/GVN/condprop.ll
+++ llvm/test/Transforms/GVN/condprop.ll
@@ -87,13 +87,13 @@
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 @@
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)
Index: llvm/lib/Transforms/Scalar/GVN.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/GVN.cpp
+++ llvm/lib/Transforms/Scalar/GVN.cpp
@@ -2087,8 +2087,8 @@
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93841.313792.patch
Type: text/x-patch
Size: 1957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201227/23deb657/attachment.bin>
More information about the llvm-commits
mailing list