1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -mtriple=aarch64-linux-gnu -O2 -o - %s | FileCheck %s
4 define i64 @test_ssub_nonneg_rhs(i64 %x) {
5 ; CHECK-LABEL: test_ssub_nonneg_rhs:
7 ; CHECK-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
8 ; CHECK-NEXT: subs x9, x0, #1
9 ; CHECK-NEXT: csel x0, x8, x9, vs
11 %sat = call i64 @llvm.ssub.sat.i64(i64 %x, i64 1)
15 define i64 @test_ssub_neg_rhs(i64 %x) {
16 ; CHECK-LABEL: test_ssub_neg_rhs:
18 ; CHECK-NEXT: mov x8, #9223372036854775807 // =0x7fffffffffffffff
19 ; CHECK-NEXT: adds x9, x0, #1
20 ; CHECK-NEXT: csel x0, x8, x9, vs
22 %sat = call i64 @llvm.ssub.sat.i64(i64 %x, i64 -1)
26 define i64 @test_sadd_nonneg_rhs(i64 %x) {
27 ; CHECK-LABEL: test_sadd_nonneg_rhs:
29 ; CHECK-NEXT: mov x8, #9223372036854775807 // =0x7fffffffffffffff
30 ; CHECK-NEXT: adds x9, x0, #1
31 ; CHECK-NEXT: csel x0, x8, x9, vs
33 %sat = call i64 @llvm.sadd.sat.i64(i64 %x, i64 1)
38 define i64 @test_sadd_neg_rhs(i64 %x) {
39 ; CHECK-LABEL: test_sadd_neg_rhs:
41 ; CHECK-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
42 ; CHECK-NEXT: subs x9, x0, #1
43 ; CHECK-NEXT: csel x0, x8, x9, vs
45 %sat = call i64 @llvm.sadd.sat.i64(i64 %x, i64 -1)
49 define i64 @test_ssub_nonneg_lhs(i64 %x) {
50 ; CHECK-LABEL: test_ssub_nonneg_lhs:
52 ; CHECK-NEXT: mov w8, #1 // =0x1
53 ; CHECK-NEXT: mov x9, #9223372036854775807 // =0x7fffffffffffffff
54 ; CHECK-NEXT: subs x8, x8, x0
55 ; CHECK-NEXT: csel x0, x9, x8, vs
57 %sat = call i64 @llvm.ssub.sat.i64(i64 1, i64 %x)
61 define i64 @test_ssub_neg_lhs(i64 %x) {
62 ; CHECK-LABEL: test_ssub_neg_lhs:
64 ; CHECK-NEXT: mov x8, #-1 // =0xffffffffffffffff
65 ; CHECK-NEXT: mov x9, #-9223372036854775808 // =0x8000000000000000
66 ; CHECK-NEXT: subs x8, x8, x0
67 ; CHECK-NEXT: csel x0, x9, x8, vs
69 %sat = call i64 @llvm.ssub.sat.i64(i64 -1, i64 %x)
73 define i64 @test_sadd_nonneg_lhs(i64 %x) {
74 ; CHECK-LABEL: test_sadd_nonneg_lhs:
76 ; CHECK-NEXT: mov x8, #9223372036854775807 // =0x7fffffffffffffff
77 ; CHECK-NEXT: adds x9, x0, #1
78 ; CHECK-NEXT: csel x0, x8, x9, vs
80 %sat = call i64 @llvm.sadd.sat.i64(i64 1, i64 %x)
84 define i64 @test_sadd_neg_lhs(i64 %x) {
85 ; CHECK-LABEL: test_sadd_neg_lhs:
87 ; CHECK-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
88 ; CHECK-NEXT: subs x9, x0, #1
89 ; CHECK-NEXT: csel x0, x8, x9, vs
91 %sat = call i64 @llvm.sadd.sat.i64(i64 -1, i64 %x)
95 define i64 @test_ssub_nonneg_rhs_nonconst(i64 %x) {
96 ; CHECK-LABEL: test_ssub_nonneg_rhs_nonconst:
98 ; CHECK-NEXT: mov w8, #123 // =0x7b
99 ; CHECK-NEXT: mov x9, #-9223372036854775808 // =0x8000000000000000
100 ; CHECK-NEXT: and x8, x0, x8
101 ; CHECK-NEXT: subs x8, x0, x8
102 ; CHECK-NEXT: csel x0, x9, x8, vs
105 %sat = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %y)
109 define i64 @test_ssub_neg_rhs_nonconst(i64 %x) {
110 ; CHECK-LABEL: test_ssub_neg_rhs_nonconst:
112 ; CHECK-NEXT: cmn x0, #1
113 ; CHECK-NEXT: mov x8, #9223372036854775807 // =0x7fffffffffffffff
114 ; CHECK-NEXT: csinv x9, x0, xzr, lt
115 ; CHECK-NEXT: subs x9, x0, x9
116 ; CHECK-NEXT: csel x0, x8, x9, vs
118 %y = call i64 @llvm.smin(i64 %x, i64 -1)
119 %sat = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %y)
123 define i64 @test_sadd_nonneg_rhs_nonconst(i64 %x) {
124 ; CHECK-LABEL: test_sadd_nonneg_rhs_nonconst:
126 ; CHECK-NEXT: cmp x0, #1
127 ; CHECK-NEXT: mov x8, #9223372036854775807 // =0x7fffffffffffffff
128 ; CHECK-NEXT: csinc x9, x0, xzr, gt
129 ; CHECK-NEXT: adds x9, x0, x9
130 ; CHECK-NEXT: csel x0, x8, x9, vs
132 %y = call i64 @llvm.smax(i64 %x, i64 1)
133 %sat = call i64 @llvm.sadd.sat.i64(i64 %x, i64 %y)
138 define i64 @test_sadd_neg_rhs_nonconst(i64 %x) {
139 ; CHECK-LABEL: test_sadd_neg_rhs_nonconst:
141 ; CHECK-NEXT: orr x9, x0, #0x8000000000000000
142 ; CHECK-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
143 ; CHECK-NEXT: adds x9, x0, x9
144 ; CHECK-NEXT: csel x0, x8, x9, vs
146 %y = or i64 %x, u0x8000000000000000
147 %sat = call i64 @llvm.sadd.sat.i64(i64 %x, i64 %y)
151 define i64 @test_ssub_nonneg_lhs_nonconst(i64 %x) {
152 ; CHECK-LABEL: test_ssub_nonneg_lhs_nonconst:
154 ; CHECK-NEXT: mov w8, #123 // =0x7b
155 ; CHECK-NEXT: mov x9, #9223372036854775807 // =0x7fffffffffffffff
156 ; CHECK-NEXT: and x8, x0, x8
157 ; CHECK-NEXT: subs x8, x8, x0
158 ; CHECK-NEXT: csel x0, x9, x8, vs
161 %sat = call i64 @llvm.ssub.sat.i64(i64 %y, i64 %x)
165 define i64 @test_ssub_neg_lhs_nonconst(i64 %x) {
166 ; CHECK-LABEL: test_ssub_neg_lhs_nonconst:
168 ; CHECK-NEXT: cmn x0, #1
169 ; CHECK-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
170 ; CHECK-NEXT: csinv x9, x0, xzr, lt
171 ; CHECK-NEXT: subs x9, x9, x0
172 ; CHECK-NEXT: csel x0, x8, x9, vs
174 %y = call i64 @llvm.smin(i64 %x, i64 -1)
175 %sat = call i64 @llvm.ssub.sat.i64(i64 %y, i64 %x)
179 define i64 @test_sadd_nonneg_lhs_nonconst(i64 %x) {
180 ; CHECK-LABEL: test_sadd_nonneg_lhs_nonconst:
182 ; CHECK-NEXT: cmp x0, #1
183 ; CHECK-NEXT: mov x8, #9223372036854775807 // =0x7fffffffffffffff
184 ; CHECK-NEXT: csinc x9, x0, xzr, gt
185 ; CHECK-NEXT: adds x9, x9, x0
186 ; CHECK-NEXT: csel x0, x8, x9, vs
188 %y = call i64 @llvm.smax(i64 %x, i64 1)
189 %sat = call i64 @llvm.sadd.sat.i64(i64 %y, i64 %x)
193 define i64 @test_sadd_neg_lhs_nonconst(i64 %x) {
194 ; CHECK-LABEL: test_sadd_neg_lhs_nonconst:
196 ; CHECK-NEXT: orr x9, x0, #0x8000000000000000
197 ; CHECK-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
198 ; CHECK-NEXT: adds x9, x9, x0
199 ; CHECK-NEXT: csel x0, x8, x9, vs
201 %y = or i64 %x, u0x8000000000000000
202 %sat = call i64 @llvm.sadd.sat.i64(i64 %y, i64 %x)
206 declare i64 @llvm.sadd.sat.i64(i64, i64)
207 declare i64 @llvm.ssub.sat.i64(i64, i64)
208 declare i64 @llvm.smax(i64, i64)
209 declare i64 @llvm.smin(i64, i64)