From a56a02bc7eda421bb43db4936e70ba7f3362ccbc Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 26 Jan 2023 12:30:37 -0500 Subject: [PATCH] [InstSimplify] add commuted variants of logical and/or pattern; NFC Existing tests were added with D138853, but that patch failed to handle all of the commutes. The poison-safety behavior is symmetric, so I'm not duplicating all of the tests that were added with that patch. --- .../test/Transforms/InstSimplify/select-logical.ll | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/llvm/test/Transforms/InstSimplify/select-logical.ll b/llvm/test/Transforms/InstSimplify/select-logical.ll index b0fc867..0fa9c68 100644 --- a/llvm/test/Transforms/InstSimplify/select-logical.ll +++ b/llvm/test/Transforms/InstSimplify/select-logical.ll @@ -184,7 +184,6 @@ define i1 @logical_or_not_and(i1 %x, i1 %y) { ret i1 %r } - ; !(X || Y) && Y --> false define i1 @logical_or_not_and_commute_or(i1 %x, i1 %y) { @@ -197,6 +196,36 @@ define i1 @logical_or_not_and_commute_or(i1 %x, i1 %y) { ret i1 %r } +; X && !(X || Y) --> false + +define i1 @logical_or_not_commute_and(i1 %x, i1 %y) { +; CHECK-LABEL: @logical_or_not_commute_and( +; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true +; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOT]], i1 false +; CHECK-NEXT: ret i1 [[R]] +; + %l.and = select i1 %x, i1 true, i1 %y + %not = xor i1 %l.and, true + %r = select i1 %x, i1 %not, i1 false + ret i1 %r +} + +; Y && !(X || Y) --> false + +define i1 @logical_or_not_commute_and_commute_or(i1 %x, i1 %y) { +; CHECK-LABEL: @logical_or_not_commute_and_commute_or( +; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]] +; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true +; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i1 [[NOT]], i1 false +; CHECK-NEXT: ret i1 [[R]] +; + %l.and = select i1 %x, i1 true, i1 %y + %not = xor i1 %l.and, true + %r = select i1 %y, i1 %not, i1 false + ret i1 %r +} + ; vector case !(X || Y) && X --> false define <3 x i1> @logical_or_not_and_vector1(<3 x i1> %x, <3 x i1> %y) { -- 2.7.4