cgp-usubo.ll
6.54 KB
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
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s
; CodeGenPrepare is expected to form overflow intrinsics to improve DAG/isel.
define i1 @usubo_ult_i64(i64 %x, i64 %y, i64* %p) nounwind {
; CHECK-LABEL: usubo_ult_i64:
; CHECK: # %bb.0:
; CHECK-NEXT: subq %rsi, %rdi
; CHECK-NEXT: setb %al
; CHECK-NEXT: movq %rdi, (%rdx)
; CHECK-NEXT: retq
%s = sub i64 %x, %y
store i64 %s, i64* %p
%ov = icmp ult i64 %x, %y
ret i1 %ov
}
; Verify insertion point for single-BB. Toggle predicate.
define i1 @usubo_ugt_i32(i32 %x, i32 %y, i32* %p) nounwind {
; CHECK-LABEL: usubo_ugt_i32:
; CHECK: # %bb.0:
; CHECK-NEXT: subl %esi, %edi
; CHECK-NEXT: setb %al
; CHECK-NEXT: movl %edi, (%rdx)
; CHECK-NEXT: retq
%ov = icmp ugt i32 %y, %x
%s = sub i32 %x, %y
store i32 %s, i32* %p
ret i1 %ov
}
; Constant operand should match.
define i1 @usubo_ugt_constant_op0_i8(i8 %x, i8* %p) nounwind {
; CHECK-LABEL: usubo_ugt_constant_op0_i8:
; CHECK: # %bb.0:
; CHECK-NEXT: movb $42, %cl
; CHECK-NEXT: subb %dil, %cl
; CHECK-NEXT: setb %al
; CHECK-NEXT: movb %cl, (%rsi)
; CHECK-NEXT: retq
%s = sub i8 42, %x
%ov = icmp ugt i8 %x, 42
store i8 %s, i8* %p
ret i1 %ov
}
; Compare with constant operand 0 is canonicalized by commuting, but verify match for non-canonical form.
define i1 @usubo_ult_constant_op0_i16(i16 %x, i16* %p) nounwind {
; CHECK-LABEL: usubo_ult_constant_op0_i16:
; CHECK: # %bb.0:
; CHECK-NEXT: movw $43, %cx
; CHECK-NEXT: subw %di, %cx
; CHECK-NEXT: setb %al
; CHECK-NEXT: movw %cx, (%rsi)
; CHECK-NEXT: retq
%s = sub i16 43, %x
%ov = icmp ult i16 43, %x
store i16 %s, i16* %p
ret i1 %ov
}
; Subtract with constant operand 1 is canonicalized to add.
define i1 @usubo_ult_constant_op1_i16(i16 %x, i16* %p) nounwind {
; CHECK-LABEL: usubo_ult_constant_op1_i16:
; CHECK: # %bb.0:
; CHECK-NEXT: subw $44, %di
; CHECK-NEXT: setb %al
; CHECK-NEXT: movw %di, (%rsi)
; CHECK-NEXT: retq
%s = add i16 %x, -44
%ov = icmp ult i16 %x, 44
store i16 %s, i16* %p
ret i1 %ov
}
define i1 @usubo_ugt_constant_op1_i8(i8 %x, i8* %p) nounwind {
; CHECK-LABEL: usubo_ugt_constant_op1_i8:
; CHECK: # %bb.0:
; CHECK-NEXT: subb $45, %dil
; CHECK-NEXT: setb %al
; CHECK-NEXT: movb %dil, (%rsi)
; CHECK-NEXT: retq
%ov = icmp ugt i8 45, %x
%s = add i8 %x, -45
store i8 %s, i8* %p
ret i1 %ov
}
; Special-case: subtract 1 changes the compare predicate and constant.
define i1 @usubo_eq_constant1_op1_i32(i32 %x, i32* %p) nounwind {
; CHECK-LABEL: usubo_eq_constant1_op1_i32:
; CHECK: # %bb.0:
; CHECK-NEXT: subl $1, %edi
; CHECK-NEXT: setb %al
; CHECK-NEXT: movl %edi, (%rsi)
; CHECK-NEXT: retq
%s = add i32 %x, -1
%ov = icmp eq i32 %x, 0
store i32 %s, i32* %p
ret i1 %ov
}
; Special-case: subtract from 0 (negate) changes the compare predicate.
define i1 @usubo_ne_constant0_op1_i32(i32 %x, i32* %p) {
; CHECK-LABEL: usubo_ne_constant0_op1_i32:
; CHECK: # %bb.0:
; CHECK-NEXT: negl %edi
; CHECK-NEXT: setb %al
; CHECK-NEXT: movl %edi, (%rsi)
; CHECK-NEXT: retq
%s = sub i32 0, %x
%ov = icmp ne i32 %x, 0
store i32 %s, i32* %p
ret i1 %ov
}
; This used to verify insertion point for multi-BB, but now we just bail out.
declare void @call(i1)
define i1 @usubo_ult_sub_dominates_i64(i64 %x, i64 %y, i64* %p, i1 %cond) nounwind {
; CHECK-LABEL: usubo_ult_sub_dominates_i64:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: testb $1, %cl
; CHECK-NEXT: je .LBB8_2
; CHECK-NEXT: # %bb.1: # %t
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: subq %rsi, %rax
; CHECK-NEXT: movq %rax, (%rdx)
; CHECK-NEXT: testb $1, %cl
; CHECK-NEXT: je .LBB8_2
; CHECK-NEXT: # %bb.3: # %end
; CHECK-NEXT: cmpq %rsi, %rdi
; CHECK-NEXT: setb %al
; CHECK-NEXT: retq
; CHECK-NEXT: .LBB8_2: # %f
; CHECK-NEXT: movl %ecx, %eax
; CHECK-NEXT: retq
entry:
br i1 %cond, label %t, label %f
t:
%s = sub i64 %x, %y
store i64 %s, i64* %p
br i1 %cond, label %end, label %f
f:
ret i1 %cond
end:
%ov = icmp ult i64 %x, %y
ret i1 %ov
}
define i1 @usubo_ult_cmp_dominates_i64(i64 %x, i64 %y, i64* %p, i1 %cond) nounwind {
; CHECK-LABEL: usubo_ult_cmp_dominates_i64:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rbp
; CHECK-NEXT: pushq %r15
; CHECK-NEXT: pushq %r14
; CHECK-NEXT: pushq %rbx
; CHECK-NEXT: pushq %rax
; CHECK-NEXT: movl %ecx, %ebp
; CHECK-NEXT: testb $1, %bpl
; CHECK-NEXT: je .LBB9_2
; CHECK-NEXT: # %bb.1: # %t
; CHECK-NEXT: movq %rdx, %r14
; CHECK-NEXT: movq %rsi, %r15
; CHECK-NEXT: movq %rdi, %rbx
; CHECK-NEXT: xorl %edi, %edi
; CHECK-NEXT: cmpq %rsi, %rbx
; CHECK-NEXT: setb %dil
; CHECK-NEXT: callq call
; CHECK-NEXT: subq %r15, %rbx
; CHECK-NEXT: jae .LBB9_2
; CHECK-NEXT: # %bb.4: # %end
; CHECK-NEXT: setb %al
; CHECK-NEXT: movq %rbx, (%r14)
; CHECK-NEXT: jmp .LBB9_3
; CHECK-NEXT: .LBB9_2: # %f
; CHECK-NEXT: movl %ebp, %eax
; CHECK-NEXT: .LBB9_3: # %f
; CHECK-NEXT: addq $8, %rsp
; CHECK-NEXT: popq %rbx
; CHECK-NEXT: popq %r14
; CHECK-NEXT: popq %r15
; CHECK-NEXT: popq %rbp
; CHECK-NEXT: retq
entry:
br i1 %cond, label %t, label %f
t:
%ov = icmp ult i64 %x, %y
call void @call(i1 %ov)
br i1 %ov, label %end, label %f
f:
ret i1 %cond
end:
%s = sub i64 %x, %y
store i64 %s, i64* %p
ret i1 %ov
}
define void @PR41129(i64* %p64) {
; CHECK-LABEL: PR41129:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: movq (%rdi), %rax
; CHECK-NEXT: testq %rax, %rax
; CHECK-NEXT: je .LBB10_2
; CHECK-NEXT: # %bb.1: # %false
; CHECK-NEXT: andl $7, %eax
; CHECK-NEXT: movq %rax, (%rdi)
; CHECK-NEXT: retq
; CHECK-NEXT: .LBB10_2: # %true
; CHECK-NEXT: decq %rax
; CHECK-NEXT: movq %rax, (%rdi)
; CHECK-NEXT: retq
entry:
%key = load i64, i64* %p64, align 8
%cond17 = icmp eq i64 %key, 0
br i1 %cond17, label %true, label %false
false:
%andval = and i64 %key, 7
store i64 %andval, i64* %p64
br label %exit
true:
%svalue = add i64 %key, -1
store i64 %svalue, i64* %p64
br label %exit
exit:
ret void
}
define i32 @PR42571(i32 %x, i32 %y) {
; CHECK-LABEL: PR42571:
; CHECK: # %bb.0:
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NEXT: leal -1(%rdi), %eax
; CHECK-NEXT: andl %edi, %eax
; CHECK-NEXT: cmpl $1, %edi
; CHECK-NEXT: cmovbl %esi, %eax
; CHECK-NEXT: retq
%tobool = icmp eq i32 %x, 0
%sub = add nsw i32 %x, -1
%and = and i32 %sub, %x
%cond = select i1 %tobool, i32 %y, i32 %and
ret i32 %cond
}