Skip to content

Commit e3e9c94

Browse files
committed
[X86][AArch64][RISCV] Add tests for combining (select c, (and X, 1), 0) -> (and (zext c), X); NFC
1 parent 720e3ba commit e3e9c94

File tree

3 files changed

+425
-0
lines changed

3 files changed

+425
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=aarch64-none-elf -verify-machineinstrs %s -o - | FileCheck %s
3+
4+
define i32 @from_cmpeq(i32 %xx, i32 %y) {
5+
; CHECK-LABEL: from_cmpeq:
6+
; CHECK: // %bb.0:
7+
; CHECK-NEXT: and w8, w1, #0x1
8+
; CHECK-NEXT: cmp w0, #9
9+
; CHECK-NEXT: csel w0, w8, wzr, eq
10+
; CHECK-NEXT: ret
11+
%x = icmp eq i32 %xx, 9
12+
%masked = and i32 %y, 1
13+
14+
%r = select i1 %x, i32 %masked, i32 0
15+
ret i32 %r
16+
}
17+
18+
define i32 @from_cmpeq_fail_bad_andmask(i32 %xx, i32 %y) {
19+
; CHECK-LABEL: from_cmpeq_fail_bad_andmask:
20+
; CHECK: // %bb.0:
21+
; CHECK-NEXT: and w8, w1, #0x3
22+
; CHECK-NEXT: cmp w0, #9
23+
; CHECK-NEXT: csel w0, w8, wzr, eq
24+
; CHECK-NEXT: ret
25+
%x = icmp eq i32 %xx, 9
26+
%masked = and i32 %y, 3
27+
%r = select i1 %x, i32 %masked, i32 0
28+
ret i32 %r
29+
}
30+
31+
define i32 @from_i1(i1 %x, i32 %y) {
32+
; CHECK-LABEL: from_i1:
33+
; CHECK: // %bb.0:
34+
; CHECK-NEXT: and w8, w1, #0x1
35+
; CHECK-NEXT: tst w0, #0x1
36+
; CHECK-NEXT: csel w0, w8, wzr, ne
37+
; CHECK-NEXT: ret
38+
%masked = and i32 %y, 1
39+
%r = select i1 %x, i32 %masked, i32 0
40+
ret i32 %r
41+
}
42+
43+
define i32 @from_trunc_i8(i8 %xx, i32 %y) {
44+
; CHECK-LABEL: from_trunc_i8:
45+
; CHECK: // %bb.0:
46+
; CHECK-NEXT: and w8, w1, #0x1
47+
; CHECK-NEXT: tst w0, #0x1
48+
; CHECK-NEXT: csel w0, w8, wzr, ne
49+
; CHECK-NEXT: ret
50+
%masked = and i32 %y, 1
51+
%x = trunc i8 %xx to i1
52+
%r = select i1 %x, i32 %masked, i32 0
53+
ret i32 %r
54+
}
55+
56+
define i32 @from_trunc_i64(i64 %xx, i32 %y) {
57+
; CHECK-LABEL: from_trunc_i64:
58+
; CHECK: // %bb.0:
59+
; CHECK-NEXT: and w8, w1, #0x1
60+
; CHECK-NEXT: tst w0, #0x1
61+
; CHECK-NEXT: csel w0, w8, wzr, ne
62+
; CHECK-NEXT: ret
63+
%masked = and i32 %y, 1
64+
%x = trunc i64 %xx to i1
65+
%r = select i1 %x, i32 %masked, i32 0
66+
ret i32 %r
67+
}
68+
69+
define i32 @from_i1_fail_bad_select0(i1 %x, i32 %y) {
70+
; CHECK-LABEL: from_i1_fail_bad_select0:
71+
; CHECK: // %bb.0:
72+
; CHECK-NEXT: and w8, w1, #0x1
73+
; CHECK-NEXT: tst w0, #0x1
74+
; CHECK-NEXT: csinc w0, w8, wzr, ne
75+
; CHECK-NEXT: ret
76+
%masked = and i32 %y, 1
77+
%r = select i1 %x, i32 %masked, i32 1
78+
ret i32 %r
79+
}
80+
81+
define i32 @from_i1_fail_bad_select1(i1 %x, i32 %y) {
82+
; CHECK-LABEL: from_i1_fail_bad_select1:
83+
; CHECK: // %bb.0:
84+
; CHECK-NEXT: and w8, w1, #0x1
85+
; CHECK-NEXT: tst w0, #0x1
86+
; CHECK-NEXT: csel w0, wzr, w8, ne
87+
; CHECK-NEXT: ret
88+
%masked = and i32 %y, 1
89+
%r = select i1 %x, i32 0, i32 %masked
90+
ret i32 %r
91+
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s -check-prefix=RV32I
4+
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5+
; RUN: | FileCheck %s -check-prefix=RV64I
6+
7+
8+
define i32 @from_cmpeq(i32 %xx, i32 %y) {
9+
; RV32I-LABEL: from_cmpeq:
10+
; RV32I: # %bb.0:
11+
; RV32I-NEXT: addi a0, a0, -9
12+
; RV32I-NEXT: seqz a0, a0
13+
; RV32I-NEXT: and a0, a1, a0
14+
; RV32I-NEXT: ret
15+
;
16+
; RV64I-LABEL: from_cmpeq:
17+
; RV64I: # %bb.0:
18+
; RV64I-NEXT: sext.w a0, a0
19+
; RV64I-NEXT: addi a0, a0, -9
20+
; RV64I-NEXT: seqz a0, a0
21+
; RV64I-NEXT: and a0, a1, a0
22+
; RV64I-NEXT: ret
23+
%x = icmp eq i32 %xx, 9
24+
%masked = and i32 %y, 1
25+
26+
%r = select i1 %x, i32 %masked, i32 0
27+
ret i32 %r
28+
}
29+
30+
define i32 @from_cmpeq_fail_bad_andmask(i32 %xx, i32 %y) {
31+
; RV32I-LABEL: from_cmpeq_fail_bad_andmask:
32+
; RV32I: # %bb.0:
33+
; RV32I-NEXT: addi a0, a0, -9
34+
; RV32I-NEXT: snez a0, a0
35+
; RV32I-NEXT: addi a0, a0, -1
36+
; RV32I-NEXT: and a0, a1, a0
37+
; RV32I-NEXT: andi a0, a0, 3
38+
; RV32I-NEXT: ret
39+
;
40+
; RV64I-LABEL: from_cmpeq_fail_bad_andmask:
41+
; RV64I: # %bb.0:
42+
; RV64I-NEXT: sext.w a0, a0
43+
; RV64I-NEXT: addi a0, a0, -9
44+
; RV64I-NEXT: snez a0, a0
45+
; RV64I-NEXT: addiw a0, a0, -1
46+
; RV64I-NEXT: and a0, a1, a0
47+
; RV64I-NEXT: andi a0, a0, 3
48+
; RV64I-NEXT: ret
49+
%x = icmp eq i32 %xx, 9
50+
%masked = and i32 %y, 3
51+
%r = select i1 %x, i32 %masked, i32 0
52+
ret i32 %r
53+
}
54+
55+
define i32 @from_i1(i1 %x, i32 %y) {
56+
; RV32I-LABEL: from_i1:
57+
; RV32I: # %bb.0:
58+
; RV32I-NEXT: and a0, a1, a0
59+
; RV32I-NEXT: andi a0, a0, 1
60+
; RV32I-NEXT: ret
61+
;
62+
; RV64I-LABEL: from_i1:
63+
; RV64I: # %bb.0:
64+
; RV64I-NEXT: and a0, a1, a0
65+
; RV64I-NEXT: andi a0, a0, 1
66+
; RV64I-NEXT: ret
67+
%masked = and i32 %y, 1
68+
%r = select i1 %x, i32 %masked, i32 0
69+
ret i32 %r
70+
}
71+
72+
define i32 @from_trunc_i8(i8 %xx, i32 %y) {
73+
; RV32I-LABEL: from_trunc_i8:
74+
; RV32I: # %bb.0:
75+
; RV32I-NEXT: and a0, a1, a0
76+
; RV32I-NEXT: andi a0, a0, 1
77+
; RV32I-NEXT: ret
78+
;
79+
; RV64I-LABEL: from_trunc_i8:
80+
; RV64I: # %bb.0:
81+
; RV64I-NEXT: and a0, a1, a0
82+
; RV64I-NEXT: andi a0, a0, 1
83+
; RV64I-NEXT: ret
84+
%masked = and i32 %y, 1
85+
%x = trunc i8 %xx to i1
86+
%r = select i1 %x, i32 %masked, i32 0
87+
ret i32 %r
88+
}
89+
90+
define i32 @from_trunc_i64(i64 %xx, i32 %y) {
91+
; RV32I-LABEL: from_trunc_i64:
92+
; RV32I: # %bb.0:
93+
; RV32I-NEXT: and a0, a2, a0
94+
; RV32I-NEXT: andi a0, a0, 1
95+
; RV32I-NEXT: ret
96+
;
97+
; RV64I-LABEL: from_trunc_i64:
98+
; RV64I: # %bb.0:
99+
; RV64I-NEXT: and a0, a1, a0
100+
; RV64I-NEXT: andi a0, a0, 1
101+
; RV64I-NEXT: ret
102+
%masked = and i32 %y, 1
103+
%x = trunc i64 %xx to i1
104+
%r = select i1 %x, i32 %masked, i32 0
105+
ret i32 %r
106+
}
107+
108+
define i32 @from_i1_fail_bad_select0(i1 %x, i32 %y) {
109+
; RV32I-LABEL: from_i1_fail_bad_select0:
110+
; RV32I: # %bb.0:
111+
; RV32I-NEXT: andi a0, a0, 1
112+
; RV32I-NEXT: bnez a0, .LBB5_2
113+
; RV32I-NEXT: # %bb.1:
114+
; RV32I-NEXT: li a0, 1
115+
; RV32I-NEXT: ret
116+
; RV32I-NEXT: .LBB5_2:
117+
; RV32I-NEXT: andi a0, a1, 1
118+
; RV32I-NEXT: ret
119+
;
120+
; RV64I-LABEL: from_i1_fail_bad_select0:
121+
; RV64I: # %bb.0:
122+
; RV64I-NEXT: andi a0, a0, 1
123+
; RV64I-NEXT: bnez a0, .LBB5_2
124+
; RV64I-NEXT: # %bb.1:
125+
; RV64I-NEXT: li a0, 1
126+
; RV64I-NEXT: ret
127+
; RV64I-NEXT: .LBB5_2:
128+
; RV64I-NEXT: andi a0, a1, 1
129+
; RV64I-NEXT: ret
130+
%masked = and i32 %y, 1
131+
%r = select i1 %x, i32 %masked, i32 1
132+
ret i32 %r
133+
}
134+
135+
define i32 @from_i1_fail_bad_select1(i1 %x, i32 %y) {
136+
; RV32I-LABEL: from_i1_fail_bad_select1:
137+
; RV32I: # %bb.0:
138+
; RV32I-NEXT: addi a0, a0, -1
139+
; RV32I-NEXT: and a0, a1, a0
140+
; RV32I-NEXT: andi a0, a0, 1
141+
; RV32I-NEXT: ret
142+
;
143+
; RV64I-LABEL: from_i1_fail_bad_select1:
144+
; RV64I: # %bb.0:
145+
; RV64I-NEXT: addiw a0, a0, -1
146+
; RV64I-NEXT: and a0, a1, a0
147+
; RV64I-NEXT: andi a0, a0, 1
148+
; RV64I-NEXT: ret
149+
%masked = and i32 %y, 1
150+
%r = select i1 %x, i32 0, i32 %masked
151+
ret i32 %r
152+
}

0 commit comments

Comments
 (0)