• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s
3
4; CodeGenPrepare is expected to form overflow intrinsics to improve DAG/isel.
5
6define i1 @usubo_ult_i64(i64 %x, i64 %y, i64* %p) nounwind {
7; CHECK-LABEL: usubo_ult_i64:
8; CHECK:       // %bb.0:
9; CHECK-NEXT:    subs x8, x0, x1
10; CHECK-NEXT:    cset w0, lo
11; CHECK-NEXT:    str x8, [x2]
12; CHECK-NEXT:    ret
13  %s = sub i64 %x, %y
14  store i64 %s, i64* %p
15  %ov = icmp ult i64 %x, %y
16  ret i1 %ov
17}
18
19; Verify insertion point for single-BB. Toggle predicate.
20
21define i1 @usubo_ugt_i32(i32 %x, i32 %y, i32* %p) nounwind {
22; CHECK-LABEL: usubo_ugt_i32:
23; CHECK:       // %bb.0:
24; CHECK-NEXT:    subs w8, w0, w1
25; CHECK-NEXT:    cset w0, lo
26; CHECK-NEXT:    str w8, [x2]
27; CHECK-NEXT:    ret
28  %ov = icmp ugt i32 %y, %x
29  %s = sub i32 %x, %y
30  store i32 %s, i32* %p
31  ret i1 %ov
32}
33
34; Constant operand should match.
35
36define i1 @usubo_ugt_constant_op0_i8(i8 %x, i8* %p) nounwind {
37; CHECK-LABEL: usubo_ugt_constant_op0_i8:
38; CHECK:       // %bb.0:
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]
45; CHECK-NEXT:    ret
46  %s = sub i8 42, %x
47  %ov = icmp ugt i8 %x, 42
48  store i8 %s, i8* %p
49  ret i1 %ov
50}
51
52; Compare with constant operand 0 is canonicalized by commuting, but verify match for non-canonical form.
53
54define i1 @usubo_ult_constant_op0_i16(i16 %x, i16* %p) nounwind {
55; CHECK-LABEL: usubo_ult_constant_op0_i16:
56; CHECK:       // %bb.0:
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]
63; CHECK-NEXT:    ret
64  %s = sub i16 43, %x
65  %ov = icmp ult i16 43, %x
66  store i16 %s, i16* %p
67  ret i1 %ov
68}
69
70; Subtract with constant operand 1 is canonicalized to add.
71
72define i1 @usubo_ult_constant_op1_i16(i16 %x, i16* %p) nounwind {
73; CHECK-LABEL: usubo_ult_constant_op1_i16:
74; CHECK:       // %bb.0:
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]
80; CHECK-NEXT:    ret
81  %s = add i16 %x, -44
82  %ov = icmp ult i16 %x, 44
83  store i16 %s, i16* %p
84  ret i1 %ov
85}
86
87define i1 @usubo_ugt_constant_op1_i8(i8 %x, i8* %p) nounwind {
88; CHECK-LABEL: usubo_ugt_constant_op1_i8:
89; CHECK:       // %bb.0:
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]
96; CHECK-NEXT:    ret
97  %ov = icmp ugt i8 45, %x
98  %s = add i8 %x, -45
99  store i8 %s, i8* %p
100  ret i1 %ov
101}
102
103; Special-case: subtract 1 changes the compare predicate and constant.
104
105define i1 @usubo_eq_constant1_op1_i32(i32 %x, i32* %p) nounwind {
106; CHECK-LABEL: usubo_eq_constant1_op1_i32:
107; CHECK:       // %bb.0:
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]
112; CHECK-NEXT:    ret
113  %s = add i32 %x, -1
114  %ov = icmp eq i32 %x, 0
115  store i32 %s, i32* %p
116  ret i1 %ov
117}
118
119; Verify insertion point for multi-BB.
120
121declare void @call(i1)
122
123define 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]
131; CHECK-NEXT:    ret
132; CHECK-NEXT:  .LBB7_2: // %f
133; CHECK-NEXT:    and w0, w3, #0x1
134; CHECK-NEXT:    ret
135entry:
136  br i1 %cond, label %t, label %f
137
138t:
139  %s = sub i64 %x, %y
140  store i64 %s, i64* %p
141  br i1 %cond, label %end, label %f
142
143f:
144  ret i1 %cond
145
146end:
147  %ov = icmp ult i64 %x, %y
148  ret i1 %ov
149}
150
151define 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
178; CHECK-NEXT:    ret
179entry:
180  br i1 %cond, label %t, label %f
181
182t:
183  %ov = icmp ult i64 %x, %y
184  call void @call(i1 %ov)
185  br i1 %ov, label %end, label %f
186
187f:
188  ret i1 %cond
189
190end:
191  %s = sub i64 %x, %y
192  store i64 %s, i64* %p
193  ret i1 %ov
194}
195
196