1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefixes=CHECK,SSE
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefixes=CHECK,SSE
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.2 | FileCheck %s --check-prefixes=CHECK,SSE
5 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx | FileCheck %s --check-prefixes=CHECK,AVX
6 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=CHECK,AVX
7 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512f | FileCheck %s --check-prefixes=CHECK,AVX
8 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx512bw | FileCheck %s --check-prefixes=CHECK,AVX
10 declare i32 @llvm.sadd.sat.i32 (i32, i32)
11 declare i64 @llvm.sadd.sat.i64 (i64, i64)
12 declare <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16>, <8 x i16>)
14 ; fold (sadd_sat x, undef) -> -1
15 define i32 @combine_undef_i32(i32 %a0) {
16 ; CHECK-LABEL: combine_undef_i32:
18 ; CHECK-NEXT: movl $-1, %eax
20 %res = call i32 @llvm.sadd.sat.i32(i32 %a0, i32 undef)
24 define <8 x i16> @combine_undef_v8i16(<8 x i16> %a0) {
25 ; SSE-LABEL: combine_undef_v8i16:
27 ; SSE-NEXT: pcmpeqd %xmm0, %xmm0
30 ; AVX-LABEL: combine_undef_v8i16:
32 ; AVX-NEXT: vpcmpeqd %xmm0, %xmm0, %xmm0
34 %res = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> undef, <8 x i16> %a0)
38 ; fold (sadd_sat c1, c2) -> c3
39 define i32 @combine_constfold_i32() {
40 ; CHECK-LABEL: combine_constfold_i32:
42 ; CHECK-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
44 %res = call i32 @llvm.sadd.sat.i32(i32 2147483647, i32 100)
48 define <8 x i16> @combine_constfold_v8i16() {
49 ; SSE-LABEL: combine_constfold_v8i16:
51 ; SSE-NEXT: movaps {{.*#+}} xmm0 = [1,0,256,65534,0,65280,32768,0]
54 ; AVX-LABEL: combine_constfold_v8i16:
56 ; AVX-NEXT: vmovaps {{.*#+}} xmm0 = [1,0,256,65534,0,65280,32768,0]
58 %res = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> <i16 0, i16 1, i16 255, i16 65535, i16 -1, i16 -255, i16 -32760, i16 1>, <8 x i16> <i16 1, i16 65535, i16 1, i16 65535, i16 1, i16 65535, i16 -10, i16 65535>)
62 define <8 x i16> @combine_constfold_undef_v8i16() {
63 ; SSE-LABEL: combine_constfold_undef_v8i16:
65 ; SSE-NEXT: movaps {{.*#+}} xmm0 = [65535,65535,65535,65534,0,65280,32768,0]
68 ; AVX-LABEL: combine_constfold_undef_v8i16:
70 ; AVX-NEXT: vmovaps {{.*#+}} xmm0 = [65535,65535,65535,65534,0,65280,32768,0]
72 %res = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> <i16 undef, i16 1, i16 undef, i16 65535, i16 -1, i16 -255, i16 -32760, i16 1>, <8 x i16> <i16 1, i16 undef, i16 undef, i16 65535, i16 1, i16 65535, i16 -10, i16 65535>)
76 ; fold (sadd_sat c, x) -> (sadd_sat x, c)
77 define i32 @combine_constant_i32(i32 %a0) {
78 ; CHECK-LABEL: combine_constant_i32:
80 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
81 ; CHECK-NEXT: leal 1(%rdi), %eax
82 ; CHECK-NEXT: sarl $31, %eax
83 ; CHECK-NEXT: addl $-2147483648, %eax # imm = 0x80000000
84 ; CHECK-NEXT: incl %edi
85 ; CHECK-NEXT: cmovnol %edi, %eax
87 %res = call i32 @llvm.sadd.sat.i32(i32 1, i32 %a0)
91 define <8 x i16> @combine_constant_v8i16(<8 x i16> %a0) {
92 ; SSE-LABEL: combine_constant_v8i16:
94 ; SSE-NEXT: paddsw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
97 ; AVX-LABEL: combine_constant_v8i16:
99 ; AVX-NEXT: vpaddsw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
101 %res = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>, <8 x i16> %a0)
105 ; fold (sadd_sat c, 0) -> x
106 define i32 @combine_zero_i32(i32 %a0) {
107 ; CHECK-LABEL: combine_zero_i32:
109 ; CHECK-NEXT: movl %edi, %eax
111 %1 = call i32 @llvm.sadd.sat.i32(i32 %a0, i32 0)
115 define <8 x i16> @combine_zero_v8i16(<8 x i16> %a0) {
116 ; CHECK-LABEL: combine_zero_v8i16:
119 %1 = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> %a0, <8 x i16> zeroinitializer)
123 ; fold (sadd_sat x, y) -> (add x, y) iff no overflow
124 define i32 @combine_no_overflow_i32(i32 %a0, i32 %a1) {
125 ; CHECK-LABEL: combine_no_overflow_i32:
127 ; CHECK-NEXT: # kill: def $esi killed $esi def $rsi
128 ; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
129 ; CHECK-NEXT: sarl $16, %edi
130 ; CHECK-NEXT: shrl $16, %esi
131 ; CHECK-NEXT: leal (%rdi,%rsi), %eax
132 ; CHECK-NEXT: sarl $31, %eax
133 ; CHECK-NEXT: addl $-2147483648, %eax # imm = 0x80000000
134 ; CHECK-NEXT: addl %edi, %esi
135 ; CHECK-NEXT: cmovnol %esi, %eax
137 %1 = ashr i32 %a0, 16
138 %2 = lshr i32 %a1, 16
139 %3 = call i32 @llvm.sadd.sat.i32(i32 %1, i32 %2)
143 define <8 x i16> @combine_no_overflow_v8i16(<8 x i16> %a0, <8 x i16> %a1) {
144 ; SSE-LABEL: combine_no_overflow_v8i16:
146 ; SSE-NEXT: psraw $10, %xmm0
147 ; SSE-NEXT: psrlw $10, %xmm1
148 ; SSE-NEXT: paddsw %xmm1, %xmm0
151 ; AVX-LABEL: combine_no_overflow_v8i16:
153 ; AVX-NEXT: vpsraw $10, %xmm0, %xmm0
154 ; AVX-NEXT: vpsrlw $10, %xmm1, %xmm1
155 ; AVX-NEXT: vpaddsw %xmm1, %xmm0, %xmm0
157 %1 = ashr <8 x i16> %a0, <i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10>
158 %2 = lshr <8 x i16> %a1, <i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10, i16 10>
159 %3 = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> %1, <8 x i16> %2)
163 ; fold (sadd_sat (shuffle x, u, m), (shuffle y, u, m)) -> (shuffle (sadd_sat x, y), u, m)
164 define <8 x i16> @combine_shuffle_shuffle_v8i16(<8 x i16> %x0, <8 x i16> %y0) {
165 ; SSE-LABEL: combine_shuffle_shuffle_v8i16:
167 ; SSE-NEXT: paddsw %xmm1, %xmm0
168 ; SSE-NEXT: pshuflw {{.*#+}} xmm0 = xmm0[3,2,1,0,4,5,6,7]
171 ; AVX-LABEL: combine_shuffle_shuffle_v8i16:
173 ; AVX-NEXT: vpaddsw %xmm1, %xmm0, %xmm0
174 ; AVX-NEXT: vpshuflw {{.*#+}} xmm0 = xmm0[3,2,1,0,4,5,6,7]
176 %x1= shufflevector <8 x i16> %x0, <8 x i16> poison, <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 4, i32 5, i32 6, i32 7>
177 %y1 = shufflevector <8 x i16> %y0, <8 x i16> poison, <8 x i32> <i32 3, i32 2, i32 1, i32 0, i32 4, i32 5, i32 6, i32 7>
178 %res = tail call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> %x1, <8 x i16> %y1)