[InstSimplify] add commuted variants of logical and/or pattern; NFC
authorSanjay Patel <spatel@rotateright.com>
Thu, 26 Jan 2023 17:30:37 +0000 (12:30 -0500)
committerSanjay Patel <spatel@rotateright.com>
Thu, 26 Jan 2023 18:38:43 +0000 (13:38 -0500)
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.

llvm/test/Transforms/InstSimplify/select-logical.ll

index b0fc867..0fa9c68 100644 (file)
@@ -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) {