1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 | FileCheck %s --check-prefix=SSE
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefix=AVX
6 ; NOTE: this is generated by utils/update_llc_test_checks.py but we can't check NAN types (PR30443),
7 ; so we need to edit it to remove the NAN constant comments
11 define float @combine_fabs_constant() {
12 ; SSE-LABEL: combine_fabs_constant:
14 ; SSE-NEXT: movss {{.*#+}} xmm0 = [2.0E+0,0.0E+0,0.0E+0,0.0E+0]
17 ; AVX-LABEL: combine_fabs_constant:
19 ; AVX-NEXT: vmovss {{.*#+}} xmm0 = [2.0E+0,0.0E+0,0.0E+0,0.0E+0]
21 %1 = call float @llvm.fabs.f32(float -2.0)
25 define <4 x float> @combine_vec_fabs_constant() {
26 ; SSE-LABEL: combine_vec_fabs_constant:
28 ; SSE-NEXT: movaps {{.*#+}} xmm0 = [0.0E+0,0.0E+0,2.0E+0,2.0E+0]
31 ; AVX-LABEL: combine_vec_fabs_constant:
33 ; AVX-NEXT: vmovaps {{.*#+}} xmm0 = [0.0E+0,0.0E+0,2.0E+0,2.0E+0]
35 %1 = call <4 x float> @llvm.fabs.v4f32(<4 x float> <float 0.0, float -0.0, float 2.0, float -2.0>)
39 ; fabs(fabs(x)) -> fabs(x)
40 define float @combine_fabs_fabs(float %a) {
41 ; SSE-LABEL: combine_fabs_fabs:
43 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
46 ; AVX-LABEL: combine_fabs_fabs:
48 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [NaN,NaN,NaN,NaN]
49 ; AVX-NEXT: vandps %xmm1, %xmm0, %xmm0
51 %1 = call float @llvm.fabs.f32(float %a)
52 %2 = call float @llvm.fabs.f32(float %1)
56 define <4 x float> @combine_vec_fabs_fabs(<4 x float> %a) {
57 ; SSE-LABEL: combine_vec_fabs_fabs:
59 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
62 ; AVX-LABEL: combine_vec_fabs_fabs:
64 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [NaN,NaN,NaN,NaN]
65 ; AVX-NEXT: vandps %xmm1, %xmm0, %xmm0
67 %1 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %a)
68 %2 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %1)
72 ; fabs(fneg(x)) -> fabs(x)
73 define float @combine_fabs_fneg(float %a) {
74 ; SSE-LABEL: combine_fabs_fneg:
76 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
79 ; AVX-LABEL: combine_fabs_fneg:
81 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [NaN,NaN,NaN,NaN]
82 ; AVX-NEXT: vandps %xmm1, %xmm0, %xmm0
84 %1 = fsub float -0.0, %a
85 %2 = call float @llvm.fabs.f32(float %1)
89 define <4 x float> @combine_vec_fabs_fneg(<4 x float> %a) {
90 ; SSE-LABEL: combine_vec_fabs_fneg:
92 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
95 ; AVX-LABEL: combine_vec_fabs_fneg:
97 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [NaN,NaN,NaN,NaN]
98 ; AVX-NEXT: vandps %xmm1, %xmm0, %xmm0
100 %1 = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %a
101 %2 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %1)
105 ; fabs(fcopysign(x, y)) -> fabs(x)
106 define float @combine_fabs_fcopysign(float %a, float %b) {
107 ; SSE-LABEL: combine_fabs_fcopysign:
109 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
112 ; AVX-LABEL: combine_fabs_fcopysign:
114 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [NaN,NaN,NaN,NaN]
115 ; AVX-NEXT: vandps %xmm1, %xmm0, %xmm0
117 %1 = call float @llvm.copysign.f32(float %a, float %b)
118 %2 = call float @llvm.fabs.f32(float %1)
122 define <4 x float> @combine_vec_fabs_fcopysign(<4 x float> %a, <4 x float> %b) {
123 ; SSE-LABEL: combine_vec_fabs_fcopysign:
125 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
128 ; AVX-LABEL: combine_vec_fabs_fcopysign:
130 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [NaN,NaN,NaN,NaN]
131 ; AVX-NEXT: vandps %xmm1, %xmm0, %xmm0
133 %1 = call <4 x float> @llvm.copysign.v4f32(<4 x float> %a, <4 x float> %b)
134 %2 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %1)
138 ; store(fabs(load())) - convert scalar to integer
139 define void @combine_fabs_int_rmw_f64(ptr %ptr) {
140 ; SSE-LABEL: combine_fabs_int_rmw_f64:
142 ; SSE-NEXT: andb $127, 7(%rdi)
145 ; AVX-LABEL: combine_fabs_int_rmw_f64:
147 ; AVX-NEXT: andb $127, 7(%rdi)
149 %1 = load double, ptr %ptr
150 %2 = call double @llvm.fabs.f64(double %1)
151 store double %2, ptr %ptr
155 define void @combine_fabs_int_f32(ptr %src, ptr %dst) {
156 ; SSE-LABEL: combine_fabs_int_f32:
158 ; SSE-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
159 ; SSE-NEXT: andl (%rdi), %eax
160 ; SSE-NEXT: movl %eax, (%rsi)
163 ; AVX-LABEL: combine_fabs_int_f32:
165 ; AVX-NEXT: movl $2147483647, %eax # imm = 0x7FFFFFFF
166 ; AVX-NEXT: andl (%rdi), %eax
167 ; AVX-NEXT: movl %eax, (%rsi)
169 %1 = load float, ptr %src
170 %2 = call float @llvm.fabs.f32(float %1)
171 store float %2, ptr %dst
175 define void @combine_fabs_int_rmw_bfloat(ptr %ptr) nounwind {
176 ; SSE-LABEL: combine_fabs_int_rmw_bfloat:
178 ; SSE-NEXT: andb $127, 1(%rdi)
181 ; AVX-LABEL: combine_fabs_int_rmw_bfloat:
183 ; AVX-NEXT: andb $127, 1(%rdi)
185 %1 = load bfloat, ptr %ptr
186 %2 = call bfloat @llvm.fabs.bf16(bfloat %1)
187 store bfloat %2, ptr %ptr
191 define void @combine_fabs_int_half(ptr %src, ptr %dst) nounwind {
192 ; SSE-LABEL: combine_fabs_int_half:
194 ; SSE-NEXT: movzwl (%rdi), %eax
195 ; SSE-NEXT: andl $32767, %eax # imm = 0x7FFF
196 ; SSE-NEXT: movw %ax, (%rsi)
199 ; AVX-LABEL: combine_fabs_int_half:
201 ; AVX-NEXT: movzwl (%rdi), %eax
202 ; AVX-NEXT: andl $32767, %eax # imm = 0x7FFF
203 ; AVX-NEXT: movw %ax, (%rsi)
205 %1 = load half, ptr %src
206 %2 = call half @llvm.fabs.f16(half %1)
207 store half %2, ptr %dst
211 ; don't convert vector to scalar
212 define void @combine_fabs_vec_int_v4f32(ptr %src, ptr %dst) {
213 ; SSE-LABEL: combine_fabs_vec_int_v4f32:
215 ; SSE-NEXT: movaps (%rdi), %xmm0
216 ; SSE-NEXT: andps {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
217 ; SSE-NEXT: movaps %xmm0, (%rsi)
220 ; AVX-LABEL: combine_fabs_vec_int_v4f32:
222 ; AVX-NEXT: vbroadcastss {{.*#+}} xmm0 = [NaN,NaN,NaN,NaN]
223 ; AVX-NEXT: vandps (%rdi), %xmm0, %xmm0
224 ; AVX-NEXT: vmovaps %xmm0, (%rsi)
226 %1 = load <4 x float>, ptr %src
227 %2 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %1)
228 store <4 x float> %2, ptr %dst
232 declare float @llvm.fabs.f32(float %p)
233 declare float @llvm.copysign.f32(float %Mag, float %Sgn)
235 declare <4 x float> @llvm.fabs.v4f32(<4 x float> %p)
236 declare <4 x float> @llvm.copysign.v4f32(<4 x float> %Mag, <4 x float> %Sgn)