Skip to content

Commit a56a02b

Browse files
committed
[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.
1 parent df04883 commit a56a02b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ define i1 @logical_or_not_and(i1 %x, i1 %y) {
184184
ret i1 %r
185185
}
186186

187-
188187
; !(X || Y) && Y --> false
189188

190189
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) {
197196
ret i1 %r
198197
}
199198

199+
; X && !(X || Y) --> false
200+
201+
define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {
202+
; CHECK-LABEL: @logical_or_not_commute_and(
203+
; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
204+
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true
205+
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOT]], i1 false
206+
; CHECK-NEXT: ret i1 [[R]]
207+
;
208+
%l.and = select i1 %x, i1 true, i1 %y
209+
%not = xor i1 %l.and, true
210+
%r = select i1 %x, i1 %not, i1 false
211+
ret i1 %r
212+
}
213+
214+
; Y && !(X || Y) --> false
215+
216+
define i1 @logical_or_not_commute_and_commute_or(i1 %x, i1 %y) {
217+
; CHECK-LABEL: @logical_or_not_commute_and_commute_or(
218+
; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
219+
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true
220+
; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i1 [[NOT]], i1 false
221+
; CHECK-NEXT: ret i1 [[R]]
222+
;
223+
%l.and = select i1 %x, i1 true, i1 %y
224+
%not = xor i1 %l.and, true
225+
%r = select i1 %y, i1 %not, i1 false
226+
ret i1 %r
227+
}
228+
200229
; vector case !(X || Y) && X --> false
201230

202231
define <3 x i1> @logical_or_not_and_vector1(<3 x i1> %x, <3 x i1> %y) {

0 commit comments

Comments
 (0)