1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=aarch64-- | FileCheck %s --check-prefixes=CHECK,CHECK-SD
3 ; RUN: llc < %s -mtriple=aarch64-- -global-isel | FileCheck %s --check-prefixes=CHECK,CHECK-GI
5 declare i4 @llvm.sadd.sat.i4(i4, i4)
6 declare i8 @llvm.sadd.sat.i8(i8, i8)
7 declare i16 @llvm.sadd.sat.i16(i16, i16)
8 declare i32 @llvm.sadd.sat.i32(i32, i32)
9 declare i64 @llvm.sadd.sat.i64(i64, i64)
11 define i32 @func32(i32 %x, i32 %y, i32 %z) nounwind {
12 ; CHECK-SD-LABEL: func32:
14 ; CHECK-SD-NEXT: mul w8, w1, w2
15 ; CHECK-SD-NEXT: adds w8, w0, w8
16 ; CHECK-SD-NEXT: asr w9, w8, #31
17 ; CHECK-SD-NEXT: eor w9, w9, #0x80000000
18 ; CHECK-SD-NEXT: csel w0, w9, w8, vs
21 ; CHECK-GI-LABEL: func32:
23 ; CHECK-GI-NEXT: mul w8, w1, w2
24 ; CHECK-GI-NEXT: mov w9, #-2147483648 // =0x80000000
25 ; CHECK-GI-NEXT: adds w8, w0, w8
26 ; CHECK-GI-NEXT: cset w10, vs
27 ; CHECK-GI-NEXT: add w9, w9, w8, asr #31
28 ; CHECK-GI-NEXT: tst w10, #0x1
29 ; CHECK-GI-NEXT: csel w0, w9, w8, ne
32 %tmp = call i32 @llvm.sadd.sat.i32(i32 %x, i32 %a)
36 define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
37 ; CHECK-SD-LABEL: func64:
39 ; CHECK-SD-NEXT: adds x8, x0, x2
40 ; CHECK-SD-NEXT: asr x9, x8, #63
41 ; CHECK-SD-NEXT: eor x9, x9, #0x8000000000000000
42 ; CHECK-SD-NEXT: csel x0, x9, x8, vs
45 ; CHECK-GI-LABEL: func64:
47 ; CHECK-GI-NEXT: mov x8, #-9223372036854775808 // =0x8000000000000000
48 ; CHECK-GI-NEXT: adds x9, x0, x2
49 ; CHECK-GI-NEXT: cset w10, vs
50 ; CHECK-GI-NEXT: add x8, x8, x9, asr #63
51 ; CHECK-GI-NEXT: tst w10, #0x1
52 ; CHECK-GI-NEXT: csel x0, x8, x9, ne
55 %tmp = call i64 @llvm.sadd.sat.i64(i64 %x, i64 %z)
59 define i16 @func16(i16 %x, i16 %y, i16 %z) nounwind {
60 ; CHECK-SD-LABEL: func16:
62 ; CHECK-SD-NEXT: mul w8, w1, w2
63 ; CHECK-SD-NEXT: sxth w9, w0
64 ; CHECK-SD-NEXT: add w8, w9, w8, sxth
65 ; CHECK-SD-NEXT: mov w9, #32767 // =0x7fff
66 ; CHECK-SD-NEXT: cmp w8, w9
67 ; CHECK-SD-NEXT: csel w8, w8, w9, lt
68 ; CHECK-SD-NEXT: mov w9, #-32768 // =0xffff8000
69 ; CHECK-SD-NEXT: cmn w8, #8, lsl #12 // =32768
70 ; CHECK-SD-NEXT: csel w0, w8, w9, gt
73 ; CHECK-GI-LABEL: func16:
75 ; CHECK-GI-NEXT: mul w8, w1, w2
76 ; CHECK-GI-NEXT: sxth w8, w8
77 ; CHECK-GI-NEXT: add w8, w8, w0, sxth
78 ; CHECK-GI-NEXT: sxth w9, w8
79 ; CHECK-GI-NEXT: sbfx w10, w8, #15, #1
80 ; CHECK-GI-NEXT: sub w10, w10, #8, lsl #12 // =32768
81 ; CHECK-GI-NEXT: cmp w8, w9
82 ; CHECK-GI-NEXT: csel w0, w10, w8, ne
85 %tmp = call i16 @llvm.sadd.sat.i16(i16 %x, i16 %a)
89 define i8 @func8(i8 %x, i8 %y, i8 %z) nounwind {
90 ; CHECK-SD-LABEL: func8:
92 ; CHECK-SD-NEXT: mul w8, w1, w2
93 ; CHECK-SD-NEXT: sxtb w9, w0
94 ; CHECK-SD-NEXT: add w8, w9, w8, sxtb
95 ; CHECK-SD-NEXT: mov w9, #127 // =0x7f
96 ; CHECK-SD-NEXT: cmp w8, #127
97 ; CHECK-SD-NEXT: csel w8, w8, w9, lt
98 ; CHECK-SD-NEXT: mov w9, #-128 // =0xffffff80
99 ; CHECK-SD-NEXT: cmn w8, #128
100 ; CHECK-SD-NEXT: csel w0, w8, w9, gt
103 ; CHECK-GI-LABEL: func8:
104 ; CHECK-GI: // %bb.0:
105 ; CHECK-GI-NEXT: mul w8, w1, w2
106 ; CHECK-GI-NEXT: sxtb w8, w8
107 ; CHECK-GI-NEXT: add w8, w8, w0, sxtb
108 ; CHECK-GI-NEXT: sxtb w9, w8
109 ; CHECK-GI-NEXT: sbfx w10, w8, #7, #1
110 ; CHECK-GI-NEXT: sub w10, w10, #128
111 ; CHECK-GI-NEXT: cmp w8, w9
112 ; CHECK-GI-NEXT: csel w0, w10, w8, ne
115 %tmp = call i8 @llvm.sadd.sat.i8(i8 %x, i8 %a)
119 define i4 @func4(i4 %x, i4 %y, i4 %z) nounwind {
120 ; CHECK-SD-LABEL: func4:
121 ; CHECK-SD: // %bb.0:
122 ; CHECK-SD-NEXT: mul w8, w1, w2
123 ; CHECK-SD-NEXT: sbfx w9, w0, #0, #4
124 ; CHECK-SD-NEXT: lsl w8, w8, #28
125 ; CHECK-SD-NEXT: add w8, w9, w8, asr #28
126 ; CHECK-SD-NEXT: mov w9, #7 // =0x7
127 ; CHECK-SD-NEXT: cmp w8, #7
128 ; CHECK-SD-NEXT: csel w8, w8, w9, lt
129 ; CHECK-SD-NEXT: mov w9, #-8 // =0xfffffff8
130 ; CHECK-SD-NEXT: cmn w8, #8
131 ; CHECK-SD-NEXT: csel w0, w8, w9, gt
134 ; CHECK-GI-LABEL: func4:
135 ; CHECK-GI: // %bb.0:
136 ; CHECK-GI-NEXT: mul w8, w1, w2
137 ; CHECK-GI-NEXT: sbfx w9, w0, #0, #4
138 ; CHECK-GI-NEXT: sbfx w8, w8, #0, #4
139 ; CHECK-GI-NEXT: add w8, w9, w8
140 ; CHECK-GI-NEXT: sbfx w9, w8, #0, #4
141 ; CHECK-GI-NEXT: asr w10, w9, #3
142 ; CHECK-GI-NEXT: cmp w8, w9
143 ; CHECK-GI-NEXT: add w10, w10, #8
144 ; CHECK-GI-NEXT: csel w0, w10, w8, ne
147 %tmp = call i4 @llvm.sadd.sat.i4(i4 %x, i4 %a)
150 ;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line: