File: rm_redundant_cmp.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (330 lines) | stat: -rw-r--r-- 11,801 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=aarch64-linux-gnuabi -O2 | FileCheck %s

; The following cases are for i16

%struct.s_signed_i16 = type { i16, i16, i16 }
%struct.s_unsigned_i16 = type { i16, i16, i16 }

@cost_s_i8_i16 = common global %struct.s_signed_i16 zeroinitializer, align 2
@cost_u_i16 = common global %struct.s_unsigned_i16 zeroinitializer, align 2

define void @test_i16_2cmp_signed_1() {
; CHECK-LABEL: test_i16_2cmp_signed_1:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_s_i8_i16
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_s_i8_i16]
; CHECK-NEXT:    ldrsh w9, [x8, #2]
; CHECK-NEXT:    ldrsh w10, [x8, #4]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.lt .LBB0_2
; CHECK-NEXT:  // %bb.1: // %if.end8.sink.split
; CHECK-NEXT:    strh w9, [x8]
; CHECK-NEXT:  .LBB0_2: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i16, ptr getelementptr inbounds (%struct.s_signed_i16, ptr @cost_s_i8_i16, i64 0, i32 1), align 2
  %1 = load i16, ptr getelementptr inbounds (%struct.s_signed_i16, ptr @cost_s_i8_i16, i64 0, i32 2), align 2
  %cmp = icmp sgt i16 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i16 %0, ptr @cost_s_i8_i16, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp eq i16 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i16 %0, ptr @cost_s_i8_i16, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

define void @test_i16_2cmp_signed_2() {
; CHECK-LABEL: test_i16_2cmp_signed_2:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_s_i8_i16
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_s_i8_i16]
; CHECK-NEXT:    ldrsh w9, [x8, #2]
; CHECK-NEXT:    ldrsh w10, [x8, #4]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.gt .LBB1_2
; CHECK-NEXT:  // %bb.1: // %if.else
; CHECK-NEXT:    mov w9, w10
; CHECK-NEXT:    b.ge .LBB1_3
; CHECK-NEXT:  .LBB1_2: // %if.end8.sink.split
; CHECK-NEXT:    strh w9, [x8]
; CHECK-NEXT:  .LBB1_3: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i16, ptr getelementptr inbounds (%struct.s_signed_i16, ptr @cost_s_i8_i16, i64 0, i32 1), align 2
  %1 = load i16, ptr getelementptr inbounds (%struct.s_signed_i16, ptr @cost_s_i8_i16, i64 0, i32 2), align 2
  %cmp = icmp sgt i16 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i16 %0, ptr @cost_s_i8_i16, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp slt i16 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i16 %1, ptr @cost_s_i8_i16, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

define void @test_i16_2cmp_unsigned_1() {
; CHECK-LABEL: test_i16_2cmp_unsigned_1:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_u_i16
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_u_i16]
; CHECK-NEXT:    ldrh w9, [x8, #2]
; CHECK-NEXT:    ldrh w10, [x8, #4]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.lo .LBB2_2
; CHECK-NEXT:  // %bb.1: // %if.end8.sink.split
; CHECK-NEXT:    strh w9, [x8]
; CHECK-NEXT:  .LBB2_2: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i16, ptr getelementptr inbounds (%struct.s_unsigned_i16, ptr @cost_u_i16, i64 0, i32 1), align 2
  %1 = load i16, ptr getelementptr inbounds (%struct.s_unsigned_i16, ptr @cost_u_i16, i64 0, i32 2), align 2
  %cmp = icmp ugt i16 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i16 %0, ptr @cost_u_i16, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp eq i16 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i16 %0, ptr @cost_u_i16, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

define void @test_i16_2cmp_unsigned_2() {
; CHECK-LABEL: test_i16_2cmp_unsigned_2:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_u_i16
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_u_i16]
; CHECK-NEXT:    ldrh w9, [x8, #2]
; CHECK-NEXT:    ldrh w10, [x8, #4]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.hi .LBB3_2
; CHECK-NEXT:  // %bb.1: // %if.else
; CHECK-NEXT:    mov w9, w10
; CHECK-NEXT:    b.hs .LBB3_3
; CHECK-NEXT:  .LBB3_2: // %if.end8.sink.split
; CHECK-NEXT:    strh w9, [x8]
; CHECK-NEXT:  .LBB3_3: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i16, ptr getelementptr inbounds (%struct.s_unsigned_i16, ptr @cost_u_i16, i64 0, i32 1), align 2
  %1 = load i16, ptr getelementptr inbounds (%struct.s_unsigned_i16, ptr @cost_u_i16, i64 0, i32 2), align 2
  %cmp = icmp ugt i16 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i16 %0, ptr @cost_u_i16, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp ult i16 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i16 %1, ptr @cost_u_i16, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

; The following cases are for i8

%struct.s_signed_i8 = type { i8, i8, i8 }
%struct.s_unsigned_i8 = type { i8, i8, i8 }

@cost_s = common global %struct.s_signed_i8 zeroinitializer, align 2
@cost_u_i8 = common global %struct.s_unsigned_i8 zeroinitializer, align 2


define void @test_i8_2cmp_signed_1() {
; CHECK-LABEL: test_i8_2cmp_signed_1:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_s
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_s]
; CHECK-NEXT:    ldrsb w9, [x8, #1]
; CHECK-NEXT:    ldrsb w10, [x8, #2]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.lt .LBB4_2
; CHECK-NEXT:  // %bb.1: // %if.end8.sink.split
; CHECK-NEXT:    strb w9, [x8]
; CHECK-NEXT:  .LBB4_2: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i8, ptr getelementptr inbounds (%struct.s_signed_i8, ptr @cost_s, i64 0, i32 1), align 2
  %1 = load i8, ptr getelementptr inbounds (%struct.s_signed_i8, ptr @cost_s, i64 0, i32 2), align 2
  %cmp = icmp sgt i8 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i8 %0, ptr @cost_s, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp eq i8 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i8 %0, ptr @cost_s, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

define void @test_i8_2cmp_signed_2() {
; CHECK-LABEL: test_i8_2cmp_signed_2:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_s
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_s]
; CHECK-NEXT:    ldrsb w9, [x8, #1]
; CHECK-NEXT:    ldrsb w10, [x8, #2]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.gt .LBB5_2
; CHECK-NEXT:  // %bb.1: // %if.else
; CHECK-NEXT:    mov w9, w10
; CHECK-NEXT:    b.ge .LBB5_3
; CHECK-NEXT:  .LBB5_2: // %if.end8.sink.split
; CHECK-NEXT:    strb w9, [x8]
; CHECK-NEXT:  .LBB5_3: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i8, ptr getelementptr inbounds (%struct.s_signed_i8, ptr @cost_s, i64 0, i32 1), align 2
  %1 = load i8, ptr getelementptr inbounds (%struct.s_signed_i8, ptr @cost_s, i64 0, i32 2), align 2
  %cmp = icmp sgt i8 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i8 %0, ptr @cost_s, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp slt i8 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i8 %1, ptr @cost_s, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

define void @test_i8_2cmp_unsigned_1() {
; CHECK-LABEL: test_i8_2cmp_unsigned_1:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_u_i8
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_u_i8]
; CHECK-NEXT:    ldrb w9, [x8, #1]
; CHECK-NEXT:    ldrb w10, [x8, #2]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.lo .LBB6_2
; CHECK-NEXT:  // %bb.1: // %if.end8.sink.split
; CHECK-NEXT:    strb w9, [x8]
; CHECK-NEXT:  .LBB6_2: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i8, ptr getelementptr inbounds (%struct.s_unsigned_i8, ptr @cost_u_i8, i64 0, i32 1), align 2
  %1 = load i8, ptr getelementptr inbounds (%struct.s_unsigned_i8, ptr @cost_u_i8, i64 0, i32 2), align 2
  %cmp = icmp ugt i8 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i8 %0, ptr @cost_u_i8, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp eq i8 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i8 %0, ptr @cost_u_i8, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

define void @test_i8_2cmp_unsigned_2() {
; CHECK-LABEL: test_i8_2cmp_unsigned_2:
; CHECK:       // %bb.0: // %entry
; CHECK-NEXT:    adrp x8, :got:cost_u_i8
; CHECK-NEXT:    ldr x8, [x8, :got_lo12:cost_u_i8]
; CHECK-NEXT:    ldrb w9, [x8, #1]
; CHECK-NEXT:    ldrb w10, [x8, #2]
; CHECK-NEXT:    cmp w9, w10
; CHECK-NEXT:    b.hi .LBB7_2
; CHECK-NEXT:  // %bb.1: // %if.else
; CHECK-NEXT:    mov w9, w10
; CHECK-NEXT:    b.hs .LBB7_3
; CHECK-NEXT:  .LBB7_2: // %if.end8.sink.split
; CHECK-NEXT:    strb w9, [x8]
; CHECK-NEXT:  .LBB7_3: // %if.end8
; CHECK-NEXT:    ret
entry:
  %0 = load i8, ptr getelementptr inbounds (%struct.s_unsigned_i8, ptr @cost_u_i8, i64 0, i32 1), align 2
  %1 = load i8, ptr getelementptr inbounds (%struct.s_unsigned_i8, ptr @cost_u_i8, i64 0, i32 2), align 2
  %cmp = icmp ugt i8 %0, %1
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  store i8 %0, ptr @cost_u_i8, align 2
  br label %if.end8

if.else:                                          ; preds = %entry
  %cmp5 = icmp ult i8 %0, %1
  br i1 %cmp5, label %if.then7, label %if.end8

if.then7:                                         ; preds = %if.else
  store i8 %1, ptr @cost_u_i8, align 2
  br label %if.end8

if.end8:                                          ; preds = %if.else, %if.then7, %if.then
  ret void
}

; Make sure the case below won't crash.

; The optimization of ZERO_EXTEND and SIGN_EXTEND in type legalization stage can't assert
; the operand of a set_cc is always a TRUNCATE.

define i1 @foo(float %inl, float %inr) {
; CHECK-LABEL: foo:
; CHECK:       // %bb.0:
; CHECK-NEXT:    fcvtzs w8, s0
; CHECK-NEXT:    fcvtzs w9, s1
; CHECK-NEXT:    cmp w8, w9
; CHECK-NEXT:    cset w0, eq
; CHECK-NEXT:    ret
  %lval = fptosi float %inl to i8
  %rval = fptosi float %inr to i8
  %sum = icmp eq i8 %lval, %rval
  ret i1 %sum
}