Skip to content

Commit f072263

Browse files
committed
[AArch64] Add some extra typepromotion cost tests. NFC
1 parent 29bb649 commit f072263

File tree

2 files changed

+221
-40
lines changed

2 files changed

+221
-40
lines changed

llvm/test/CodeGen/AArch64/rm_redundant_cmp.ll

Lines changed: 116 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
12
; RUN: llc < %s -mtriple=aarch64-linux-gnuabi -O2 | FileCheck %s
23

34
; The following cases are for i16
@@ -9,11 +10,18 @@
910
@cost_u_i16 = common global %struct.s_unsigned_i16 zeroinitializer, align 2
1011

1112
define void @test_i16_2cmp_signed_1() {
12-
; CHECK-LABEL: test_i16_2cmp_signed_1
13-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
14-
; CHECK-NEXT: b.lt
15-
; CHECK-NOT: cmp
16-
; CHECK: ret
13+
; CHECK-LABEL: test_i16_2cmp_signed_1:
14+
; CHECK: // %bb.0: // %entry
15+
; CHECK-NEXT: adrp x8, :got:cost_s_i8_i16
16+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_s_i8_i16]
17+
; CHECK-NEXT: ldrsh w9, [x8, #2]
18+
; CHECK-NEXT: ldrsh w10, [x8, #4]
19+
; CHECK-NEXT: cmp w9, w10
20+
; CHECK-NEXT: b.lt .LBB0_2
21+
; CHECK-NEXT: // %bb.1: // %if.end8.sink.split
22+
; CHECK-NEXT: strh w9, [x8]
23+
; CHECK-NEXT: .LBB0_2: // %if.end8
24+
; CHECK-NEXT: ret
1725
entry:
1826
%0 = load i16, i16* getelementptr inbounds (%struct.s_signed_i16, %struct.s_signed_i16* @cost_s_i8_i16, i64 0, i32 1), align 2
1927
%1 = load i16, i16* getelementptr inbounds (%struct.s_signed_i16, %struct.s_signed_i16* @cost_s_i8_i16, i64 0, i32 2), align 2
@@ -37,11 +45,21 @@ if.end8: ; preds = %if.else, %if.then7,
3745
}
3846

3947
define void @test_i16_2cmp_signed_2() {
40-
; CHECK-LABEL: test_i16_2cmp_signed_2
41-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
42-
; CHECK-NEXT: b.gt
43-
; CHECK-NOT: cmp
44-
; CHECK: b.ge
48+
; CHECK-LABEL: test_i16_2cmp_signed_2:
49+
; CHECK: // %bb.0: // %entry
50+
; CHECK-NEXT: adrp x8, :got:cost_s_i8_i16
51+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_s_i8_i16]
52+
; CHECK-NEXT: ldrsh w9, [x8, #2]
53+
; CHECK-NEXT: ldrsh w10, [x8, #4]
54+
; CHECK-NEXT: cmp w9, w10
55+
; CHECK-NEXT: b.gt .LBB1_2
56+
; CHECK-NEXT: // %bb.1: // %if.else
57+
; CHECK-NEXT: mov w9, w10
58+
; CHECK-NEXT: b.ge .LBB1_3
59+
; CHECK-NEXT: .LBB1_2: // %if.end8.sink.split
60+
; CHECK-NEXT: strh w9, [x8]
61+
; CHECK-NEXT: .LBB1_3: // %if.end8
62+
; CHECK-NEXT: ret
4563
entry:
4664
%0 = load i16, i16* getelementptr inbounds (%struct.s_signed_i16, %struct.s_signed_i16* @cost_s_i8_i16, i64 0, i32 1), align 2
4765
%1 = load i16, i16* getelementptr inbounds (%struct.s_signed_i16, %struct.s_signed_i16* @cost_s_i8_i16, i64 0, i32 2), align 2
@@ -65,11 +83,18 @@ if.end8: ; preds = %if.else, %if.then7,
6583
}
6684

6785
define void @test_i16_2cmp_unsigned_1() {
68-
; CHECK-LABEL: test_i16_2cmp_unsigned_1
69-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
70-
; CHECK-NEXT: b.lo
71-
; CHECK-NOT: cmp
72-
; CHECK: ret
86+
; CHECK-LABEL: test_i16_2cmp_unsigned_1:
87+
; CHECK: // %bb.0: // %entry
88+
; CHECK-NEXT: adrp x8, :got:cost_u_i16
89+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_u_i16]
90+
; CHECK-NEXT: ldrh w9, [x8, #2]
91+
; CHECK-NEXT: ldrh w10, [x8, #4]
92+
; CHECK-NEXT: cmp w9, w10
93+
; CHECK-NEXT: b.lo .LBB2_2
94+
; CHECK-NEXT: // %bb.1: // %if.end8.sink.split
95+
; CHECK-NEXT: strh w9, [x8]
96+
; CHECK-NEXT: .LBB2_2: // %if.end8
97+
; CHECK-NEXT: ret
7398
entry:
7499
%0 = load i16, i16* getelementptr inbounds (%struct.s_unsigned_i16, %struct.s_unsigned_i16* @cost_u_i16, i64 0, i32 1), align 2
75100
%1 = load i16, i16* getelementptr inbounds (%struct.s_unsigned_i16, %struct.s_unsigned_i16* @cost_u_i16, i64 0, i32 2), align 2
@@ -93,11 +118,21 @@ if.end8: ; preds = %if.else, %if.then7,
93118
}
94119

95120
define void @test_i16_2cmp_unsigned_2() {
96-
; CHECK-LABEL: test_i16_2cmp_unsigned_2
97-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
98-
; CHECK-NEXT: b.hi
99-
; CHECK-NOT: cmp
100-
; CHECK: b.hs
121+
; CHECK-LABEL: test_i16_2cmp_unsigned_2:
122+
; CHECK: // %bb.0: // %entry
123+
; CHECK-NEXT: adrp x8, :got:cost_u_i16
124+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_u_i16]
125+
; CHECK-NEXT: ldrh w9, [x8, #2]
126+
; CHECK-NEXT: ldrh w10, [x8, #4]
127+
; CHECK-NEXT: cmp w9, w10
128+
; CHECK-NEXT: b.hi .LBB3_2
129+
; CHECK-NEXT: // %bb.1: // %if.else
130+
; CHECK-NEXT: mov w9, w10
131+
; CHECK-NEXT: b.hs .LBB3_3
132+
; CHECK-NEXT: .LBB3_2: // %if.end8.sink.split
133+
; CHECK-NEXT: strh w9, [x8]
134+
; CHECK-NEXT: .LBB3_3: // %if.end8
135+
; CHECK-NEXT: ret
101136
entry:
102137
%0 = load i16, i16* getelementptr inbounds (%struct.s_unsigned_i16, %struct.s_unsigned_i16* @cost_u_i16, i64 0, i32 1), align 2
103138
%1 = load i16, i16* getelementptr inbounds (%struct.s_unsigned_i16, %struct.s_unsigned_i16* @cost_u_i16, i64 0, i32 2), align 2
@@ -130,11 +165,18 @@ if.end8: ; preds = %if.else, %if.then7,
130165

131166

132167
define void @test_i8_2cmp_signed_1() {
133-
; CHECK-LABEL: test_i8_2cmp_signed_1
134-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
135-
; CHECK-NEXT: b.lt
136-
; CHECK-NOT: cmp
137-
; CHECK: ret
168+
; CHECK-LABEL: test_i8_2cmp_signed_1:
169+
; CHECK: // %bb.0: // %entry
170+
; CHECK-NEXT: adrp x8, :got:cost_s
171+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_s]
172+
; CHECK-NEXT: ldrsb w9, [x8, #1]
173+
; CHECK-NEXT: ldrsb w10, [x8, #2]
174+
; CHECK-NEXT: cmp w9, w10
175+
; CHECK-NEXT: b.lt .LBB4_2
176+
; CHECK-NEXT: // %bb.1: // %if.end8.sink.split
177+
; CHECK-NEXT: strb w9, [x8]
178+
; CHECK-NEXT: .LBB4_2: // %if.end8
179+
; CHECK-NEXT: ret
138180
entry:
139181
%0 = load i8, i8* getelementptr inbounds (%struct.s_signed_i8, %struct.s_signed_i8* @cost_s, i64 0, i32 1), align 2
140182
%1 = load i8, i8* getelementptr inbounds (%struct.s_signed_i8, %struct.s_signed_i8* @cost_s, i64 0, i32 2), align 2
@@ -158,11 +200,21 @@ if.end8: ; preds = %if.else, %if.then7,
158200
}
159201

160202
define void @test_i8_2cmp_signed_2() {
161-
; CHECK-LABEL: test_i8_2cmp_signed_2
162-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
163-
; CHECK-NEXT: b.gt
164-
; CHECK-NOT: cmp
165-
; CHECK: b.ge
203+
; CHECK-LABEL: test_i8_2cmp_signed_2:
204+
; CHECK: // %bb.0: // %entry
205+
; CHECK-NEXT: adrp x8, :got:cost_s
206+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_s]
207+
; CHECK-NEXT: ldrsb w9, [x8, #1]
208+
; CHECK-NEXT: ldrsb w10, [x8, #2]
209+
; CHECK-NEXT: cmp w9, w10
210+
; CHECK-NEXT: b.gt .LBB5_2
211+
; CHECK-NEXT: // %bb.1: // %if.else
212+
; CHECK-NEXT: mov w9, w10
213+
; CHECK-NEXT: b.ge .LBB5_3
214+
; CHECK-NEXT: .LBB5_2: // %if.end8.sink.split
215+
; CHECK-NEXT: strb w9, [x8]
216+
; CHECK-NEXT: .LBB5_3: // %if.end8
217+
; CHECK-NEXT: ret
166218
entry:
167219
%0 = load i8, i8* getelementptr inbounds (%struct.s_signed_i8, %struct.s_signed_i8* @cost_s, i64 0, i32 1), align 2
168220
%1 = load i8, i8* getelementptr inbounds (%struct.s_signed_i8, %struct.s_signed_i8* @cost_s, i64 0, i32 2), align 2
@@ -186,11 +238,18 @@ if.end8: ; preds = %if.else, %if.then7,
186238
}
187239

188240
define void @test_i8_2cmp_unsigned_1() {
189-
; CHECK-LABEL: test_i8_2cmp_unsigned_1
190-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
191-
; CHECK-NEXT: b.lo
192-
; CHECK-NOT: cmp
193-
; CHECK: ret
241+
; CHECK-LABEL: test_i8_2cmp_unsigned_1:
242+
; CHECK: // %bb.0: // %entry
243+
; CHECK-NEXT: adrp x8, :got:cost_u_i8
244+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_u_i8]
245+
; CHECK-NEXT: ldrb w9, [x8, #1]
246+
; CHECK-NEXT: ldrb w10, [x8, #2]
247+
; CHECK-NEXT: cmp w9, w10
248+
; CHECK-NEXT: b.lo .LBB6_2
249+
; CHECK-NEXT: // %bb.1: // %if.end8.sink.split
250+
; CHECK-NEXT: strb w9, [x8]
251+
; CHECK-NEXT: .LBB6_2: // %if.end8
252+
; CHECK-NEXT: ret
194253
entry:
195254
%0 = load i8, i8* getelementptr inbounds (%struct.s_unsigned_i8, %struct.s_unsigned_i8* @cost_u_i8, i64 0, i32 1), align 2
196255
%1 = load i8, i8* getelementptr inbounds (%struct.s_unsigned_i8, %struct.s_unsigned_i8* @cost_u_i8, i64 0, i32 2), align 2
@@ -214,11 +273,21 @@ if.end8: ; preds = %if.else, %if.then7,
214273
}
215274

216275
define void @test_i8_2cmp_unsigned_2() {
217-
; CHECK-LABEL: test_i8_2cmp_unsigned_2
218-
; CHECK: cmp {{w[0-9]+}}, {{w[0-9]+}}
219-
; CHECK-NEXT: b.hi
220-
; CHECK-NOT: cmp
221-
; CHECK: b.hs
276+
; CHECK-LABEL: test_i8_2cmp_unsigned_2:
277+
; CHECK: // %bb.0: // %entry
278+
; CHECK-NEXT: adrp x8, :got:cost_u_i8
279+
; CHECK-NEXT: ldr x8, [x8, :got_lo12:cost_u_i8]
280+
; CHECK-NEXT: ldrb w9, [x8, #1]
281+
; CHECK-NEXT: ldrb w10, [x8, #2]
282+
; CHECK-NEXT: cmp w9, w10
283+
; CHECK-NEXT: b.hi .LBB7_2
284+
; CHECK-NEXT: // %bb.1: // %if.else
285+
; CHECK-NEXT: mov w9, w10
286+
; CHECK-NEXT: b.hs .LBB7_3
287+
; CHECK-NEXT: .LBB7_2: // %if.end8.sink.split
288+
; CHECK-NEXT: strb w9, [x8]
289+
; CHECK-NEXT: .LBB7_3: // %if.end8
290+
; CHECK-NEXT: ret
222291
entry:
223292
%0 = load i8, i8* getelementptr inbounds (%struct.s_unsigned_i8, %struct.s_unsigned_i8* @cost_u_i8, i64 0, i32 1), align 2
224293
%1 = load i8, i8* getelementptr inbounds (%struct.s_unsigned_i8, %struct.s_unsigned_i8* @cost_u_i8, i64 0, i32 2), align 2
@@ -247,6 +316,13 @@ if.end8: ; preds = %if.else, %if.then7,
247316
; the operand of a set_cc is always a TRUNCATE.
248317

249318
define i1 @foo(float %inl, float %inr) {
319+
; CHECK-LABEL: foo:
320+
; CHECK: // %bb.0:
321+
; CHECK-NEXT: fcvtzs w8, s0
322+
; CHECK-NEXT: fcvtzs w9, s1
323+
; CHECK-NEXT: cmp w8, w9
324+
; CHECK-NEXT: cset w0, eq
325+
; CHECK-NEXT: ret
250326
%lval = fptosi float %inl to i8
251327
%rval = fptosi float %inr to i8
252328
%sum = icmp eq i8 %lval, %rval
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -o - %s -mtriple=aarch64-none-eabi | FileCheck %s --check-prefix=CHECK-O2
3+
; RUN: llc -o - %s -mtriple=aarch64-none-eabi -O3 | FileCheck %s --check-prefix=CHECK-O3
4+
5+
%struct.S = type { i32, i16 }
6+
define i32 @needless_promotion(ptr nocapture noundef readonly %S, i64 noundef %red_cost) {
7+
; CHECK-O2-LABEL: needless_promotion:
8+
; CHECK-O2: // %bb.0: // %entry
9+
; CHECK-O2-NEXT: ldrsh w8, [x0, #4]
10+
; CHECK-O2-NEXT: tbnz w8, #31, .LBB0_3
11+
; CHECK-O2-NEXT: // %bb.1: // %lor.rhs
12+
; CHECK-O2-NEXT: cbz x1, .LBB0_5
13+
; CHECK-O2-NEXT: // %bb.2:
14+
; CHECK-O2-NEXT: mov w9, #2
15+
; CHECK-O2-NEXT: b .LBB0_4
16+
; CHECK-O2-NEXT: .LBB0_3:
17+
; CHECK-O2-NEXT: mov w9, #1
18+
; CHECK-O2-NEXT: .LBB0_4: // %lor.end.sink.split
19+
; CHECK-O2-NEXT: and w8, w8, #0xffff
20+
; CHECK-O2-NEXT: cmp w8, w9
21+
; CHECK-O2-NEXT: cset w0, eq
22+
; CHECK-O2-NEXT: ret
23+
; CHECK-O2-NEXT: .LBB0_5:
24+
; CHECK-O2-NEXT: mov w0, wzr
25+
; CHECK-O2-NEXT: ret
26+
;
27+
; CHECK-O3-LABEL: needless_promotion:
28+
; CHECK-O3: // %bb.0: // %entry
29+
; CHECK-O3-NEXT: ldrsh w8, [x0, #4]
30+
; CHECK-O3-NEXT: tbnz w8, #31, .LBB0_3
31+
; CHECK-O3-NEXT: // %bb.1: // %lor.rhs
32+
; CHECK-O3-NEXT: cbz x1, .LBB0_4
33+
; CHECK-O3-NEXT: // %bb.2:
34+
; CHECK-O3-NEXT: mov w9, #2
35+
; CHECK-O3-NEXT: and w8, w8, #0xffff
36+
; CHECK-O3-NEXT: cmp w8, w9
37+
; CHECK-O3-NEXT: cset w0, eq
38+
; CHECK-O3-NEXT: ret
39+
; CHECK-O3-NEXT: .LBB0_3:
40+
; CHECK-O3-NEXT: mov w9, #1
41+
; CHECK-O3-NEXT: and w8, w8, #0xffff
42+
; CHECK-O3-NEXT: cmp w8, w9
43+
; CHECK-O3-NEXT: cset w0, eq
44+
; CHECK-O3-NEXT: ret
45+
; CHECK-O3-NEXT: .LBB0_4:
46+
; CHECK-O3-NEXT: mov w0, wzr
47+
; CHECK-O3-NEXT: ret
48+
entry:
49+
%ident = getelementptr inbounds %struct.S, ptr %S, i64 0, i32 1
50+
%0 = load i16, ptr %ident, align 8
51+
%cmp = icmp slt i16 %0, 0
52+
br i1 %cmp, label %lor.end.sink.split, label %lor.rhs
53+
54+
lor.rhs: ; preds = %entry
55+
%cmp3.not = icmp eq i64 %red_cost, 0
56+
br i1 %cmp3.not, label %lor.end, label %lor.end.sink.split
57+
58+
lor.end.sink.split: ; preds = %lor.rhs, %entry
59+
%.sink12 = phi i16 [ 1, %entry ], [ 2, %lor.rhs ]
60+
%cmp1 = icmp eq i16 %0, %.sink12
61+
%phi.cast = zext i1 %cmp1 to i32
62+
br label %lor.end
63+
64+
lor.end: ; preds = %lor.end.sink.split, %lor.rhs
65+
%.shrunk = phi i32 [ 0, %lor.rhs ], [ %phi.cast, %lor.end.sink.split ]
66+
ret i32 %.shrunk
67+
}
68+
69+
define i8 @loopcmp(ptr nocapture noundef readonly %x, i8 noundef %y) {
70+
; CHECK-O2-LABEL: loopcmp:
71+
; CHECK-O2: // %bb.0: // %entry
72+
; CHECK-O2-NEXT: .LBB1_1: // %while.cond
73+
; CHECK-O2-NEXT: // =>This Inner Loop Header: Depth=1
74+
; CHECK-O2-NEXT: ldrb w8, [x0], #1
75+
; CHECK-O2-NEXT: cmp w8, w1, uxtb
76+
; CHECK-O2-NEXT: b.lo .LBB1_1
77+
; CHECK-O2-NEXT: // %bb.2: // %while.end
78+
; CHECK-O2-NEXT: mov w0, w8
79+
; CHECK-O2-NEXT: ret
80+
;
81+
; CHECK-O3-LABEL: loopcmp:
82+
; CHECK-O3: // %bb.0: // %entry
83+
; CHECK-O3-NEXT: and w9, w1, #0xff
84+
; CHECK-O3-NEXT: .LBB1_1: // %while.cond
85+
; CHECK-O3-NEXT: // =>This Inner Loop Header: Depth=1
86+
; CHECK-O3-NEXT: ldrb w8, [x0], #1
87+
; CHECK-O3-NEXT: cmp w8, w9
88+
; CHECK-O3-NEXT: b.lo .LBB1_1
89+
; CHECK-O3-NEXT: // %bb.2: // %while.end
90+
; CHECK-O3-NEXT: mov w0, w8
91+
; CHECK-O3-NEXT: ret
92+
entry:
93+
br label %while.cond
94+
95+
while.cond: ; preds = %while.cond, %entry
96+
%a.0.in = phi ptr [ %x, %entry ], [ %x.addr.0, %while.cond ]
97+
%a.0 = load i8, ptr %a.0.in, align 1
98+
%cmp = icmp ult i8 %a.0, %y
99+
%x.addr.0 = getelementptr inbounds i8, ptr %a.0.in, i64 1
100+
br i1 %cmp, label %while.cond, label %while.end
101+
102+
while.end: ; preds = %while.cond
103+
ret i8 %a.0
104+
}
105+

0 commit comments

Comments
 (0)