1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s
4 ; CodeGenPrepare is expected to form overflow intrinsics to improve DAG/isel.
6 define i1 @usubo_ult_i64(i64 %x, i64 %y, i64* %p) nounwind {
7 ; CHECK-LABEL: usubo_ult_i64:
9 ; CHECK-NEXT: subs x8, x0, x1
10 ; CHECK-NEXT: cset w0, lo
11 ; CHECK-NEXT: str x8, [x2]
15 %ov = icmp ult i64 %x, %y
19 ; Verify insertion point for single-BB. Toggle predicate.
21 define i1 @usubo_ugt_i32(i32 %x, i32 %y, i32* %p) nounwind {
22 ; CHECK-LABEL: usubo_ugt_i32:
24 ; CHECK-NEXT: subs w8, w0, w1
25 ; CHECK-NEXT: cset w0, lo
26 ; CHECK-NEXT: str w8, [x2]
28 %ov = icmp ugt i32 %y, %x
34 ; Constant operand should match.
36 define i1 @usubo_ugt_constant_op0_i8(i8 %x, i8* %p) nounwind {
37 ; CHECK-LABEL: usubo_ugt_constant_op0_i8:
39 ; CHECK-NEXT: and w8, w0, #0xff
40 ; CHECK-NEXT: mov w9, #42
41 ; CHECK-NEXT: cmp w8, #42 // =42
42 ; CHECK-NEXT: sub w9, w9, w0
43 ; CHECK-NEXT: cset w0, hi
44 ; CHECK-NEXT: strb w9, [x1]
47 %ov = icmp ugt i8 %x, 42
52 ; Compare with constant operand 0 is canonicalized by commuting, but verify match for non-canonical form.
54 define i1 @usubo_ult_constant_op0_i16(i16 %x, i16* %p) nounwind {
55 ; CHECK-LABEL: usubo_ult_constant_op0_i16:
57 ; CHECK-NEXT: and w8, w0, #0xffff
58 ; CHECK-NEXT: mov w9, #43
59 ; CHECK-NEXT: cmp w8, #43 // =43
60 ; CHECK-NEXT: sub w9, w9, w0
61 ; CHECK-NEXT: cset w0, hi
62 ; CHECK-NEXT: strh w9, [x1]
65 %ov = icmp ult i16 43, %x
70 ; Subtract with constant operand 1 is canonicalized to add.
72 define i1 @usubo_ult_constant_op1_i16(i16 %x, i16* %p) nounwind {
73 ; CHECK-LABEL: usubo_ult_constant_op1_i16:
75 ; CHECK-NEXT: and w8, w0, #0xffff
76 ; CHECK-NEXT: cmp w8, #44 // =44
77 ; CHECK-NEXT: sub w9, w0, #44 // =44
78 ; CHECK-NEXT: cset w0, lo
79 ; CHECK-NEXT: strh w9, [x1]
82 %ov = icmp ult i16 %x, 44
87 define i1 @usubo_ugt_constant_op1_i8(i8 %x, i8* %p) nounwind {
88 ; CHECK-LABEL: usubo_ugt_constant_op1_i8:
90 ; CHECK-NEXT: and w8, w0, #0xff
91 ; CHECK-NEXT: cmp w8, #45 // =45
92 ; CHECK-NEXT: cset w8, lo
93 ; CHECK-NEXT: sub w9, w0, #45 // =45
94 ; CHECK-NEXT: mov w0, w8
95 ; CHECK-NEXT: strb w9, [x1]
97 %ov = icmp ugt i8 45, %x
103 ; Special-case: subtract 1 changes the compare predicate and constant.
105 define i1 @usubo_eq_constant1_op1_i32(i32 %x, i32* %p) nounwind {
106 ; CHECK-LABEL: usubo_eq_constant1_op1_i32:
108 ; CHECK-NEXT: cmp w0, #0 // =0
109 ; CHECK-NEXT: sub w8, w0, #1 // =1
110 ; CHECK-NEXT: cset w0, eq
111 ; CHECK-NEXT: str w8, [x1]
114 %ov = icmp eq i32 %x, 0
115 store i32 %s, i32* %p
119 ; Verify insertion point for multi-BB.
121 declare void @call(i1)
123 define i1 @usubo_ult_sub_dominates_i64(i64 %x, i64 %y, i64* %p, i1 %cond) nounwind {
124 ; CHECK-LABEL: usubo_ult_sub_dominates_i64:
125 ; CHECK: // %bb.0: // %entry
126 ; CHECK-NEXT: tbz w3, #0, .LBB7_2
127 ; CHECK-NEXT: // %bb.1: // %t
128 ; CHECK-NEXT: subs x8, x0, x1
129 ; CHECK-NEXT: cset w0, lo
130 ; CHECK-NEXT: str x8, [x2]
132 ; CHECK-NEXT: .LBB7_2: // %f
133 ; CHECK-NEXT: and w0, w3, #0x1
136 br i1 %cond, label %t, label %f
140 store i64 %s, i64* %p
141 br i1 %cond, label %end, label %f
147 %ov = icmp ult i64 %x, %y
151 define i1 @usubo_ult_cmp_dominates_i64(i64 %x, i64 %y, i64* %p, i1 %cond) nounwind {
152 ; CHECK-LABEL: usubo_ult_cmp_dominates_i64:
153 ; CHECK: // %bb.0: // %entry
154 ; CHECK-NEXT: str x30, [sp, #-48]! // 8-byte Folded Spill
155 ; CHECK-NEXT: stp x20, x19, [sp, #32] // 16-byte Folded Spill
156 ; CHECK-NEXT: mov w20, w3
157 ; CHECK-NEXT: stp x22, x21, [sp, #16] // 16-byte Folded Spill
158 ; CHECK-NEXT: tbz w3, #0, .LBB8_3
159 ; CHECK-NEXT: // %bb.1: // %t
160 ; CHECK-NEXT: cmp x0, x1
161 ; CHECK-NEXT: mov x22, x0
162 ; CHECK-NEXT: cset w0, lo
163 ; CHECK-NEXT: mov x19, x2
164 ; CHECK-NEXT: mov x21, x1
165 ; CHECK-NEXT: bl call
166 ; CHECK-NEXT: subs x8, x22, x21
167 ; CHECK-NEXT: b.hs .LBB8_3
168 ; CHECK-NEXT: // %bb.2: // %end
169 ; CHECK-NEXT: cset w0, lo
170 ; CHECK-NEXT: str x8, [x19]
171 ; CHECK-NEXT: b .LBB8_4
172 ; CHECK-NEXT: .LBB8_3: // %f
173 ; CHECK-NEXT: and w0, w20, #0x1
174 ; CHECK-NEXT: .LBB8_4: // %f
175 ; CHECK-NEXT: ldp x20, x19, [sp, #32] // 16-byte Folded Reload
176 ; CHECK-NEXT: ldp x22, x21, [sp, #16] // 16-byte Folded Reload
177 ; CHECK-NEXT: ldr x30, [sp], #48 // 8-byte Folded Reload
180 br i1 %cond, label %t, label %f
183 %ov = icmp ult i64 %x, %y
184 call void @call(i1 %ov)
185 br i1 %ov, label %end, label %f
192 store i64 %s, i64* %p