Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 80956de

Browse files
committed
[NFC][CodeGen] Add unary FNeg tests to X86/combine-fcopysign.ll X86/dag-fmf-cse.ll X86/fast-isel-fneg.ll X86/fdiv.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363093 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 49ae598 commit 80956de

File tree

4 files changed

+181
-0
lines changed

4 files changed

+181
-0
lines changed

test/CodeGen/X86/combine-fcopysign.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ define <4 x float> @combine_vec_fcopysign_fneg_fabs_sgn(<4 x float> %x, <4 x flo
102102
ret <4 x float> %3
103103
}
104104

105+
define <4 x float> @combine_vec_fcopysign_unary_fneg_fabs_sgn(<4 x float> %x, <4 x float> %y) {
106+
; SSE-LABEL: combine_vec_fcopysign_unary_fneg_fabs_sgn:
107+
; SSE: # %bb.0:
108+
; SSE-NEXT: orps {{.*}}(%rip), %xmm0
109+
; SSE-NEXT: retq
110+
;
111+
; AVX-LABEL: combine_vec_fcopysign_unary_fneg_fabs_sgn:
112+
; AVX: # %bb.0:
113+
; AVX-NEXT: vbroadcastss {{.*#+}} xmm1 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
114+
; AVX-NEXT: vorps %xmm1, %xmm0, %xmm0
115+
; AVX-NEXT: retq
116+
%1 = call <4 x float> @llvm.fabs.v4f32(<4 x float> %y)
117+
%2 = fneg <4 x float> %1
118+
%3 = call <4 x float> @llvm.copysign.v4f32(<4 x float> %x, <4 x float> %2)
119+
ret <4 x float> %3
120+
}
121+
105122
; copysign(fabs(x), y) -> copysign(x, y)
106123
define <4 x float> @combine_vec_fcopysign_fabs_mag(<4 x float> %x, <4 x float> %y) {
107124
; SSE-LABEL: combine_vec_fcopysign_fabs_mag:
@@ -146,6 +163,27 @@ define <4 x float> @combine_vec_fcopysign_fneg_mag(<4 x float> %x, <4 x float> %
146163
ret <4 x float> %2
147164
}
148165

166+
define <4 x float> @combine_vec_fcopysign_unary_fneg_mag(<4 x float> %x, <4 x float> %y) {
167+
; SSE-LABEL: combine_vec_fcopysign_unary_fneg_mag:
168+
; SSE: # %bb.0:
169+
; SSE-NEXT: andps {{.*}}(%rip), %xmm1
170+
; SSE-NEXT: andps {{.*}}(%rip), %xmm0
171+
; SSE-NEXT: orps %xmm1, %xmm0
172+
; SSE-NEXT: retq
173+
;
174+
; AVX-LABEL: combine_vec_fcopysign_unary_fneg_mag:
175+
; AVX: # %bb.0:
176+
; AVX-NEXT: vbroadcastss {{.*#+}} xmm2 = [-0.0E+0,-0.0E+0,-0.0E+0,-0.0E+0]
177+
; AVX-NEXT: vandps %xmm2, %xmm1, %xmm1
178+
; AVX-NEXT: vbroadcastss {{.*#+}} xmm2 = [NaN,NaN,NaN,NaN]
179+
; AVX-NEXT: vandps %xmm2, %xmm0, %xmm0
180+
; AVX-NEXT: vorps %xmm1, %xmm0, %xmm0
181+
; AVX-NEXT: retq
182+
%1 = fneg <4 x float> %x
183+
%2 = call <4 x float> @llvm.copysign.v4f32(<4 x float> %1, <4 x float> %y)
184+
ret <4 x float> %2
185+
}
186+
149187
; copysign(copysign(x,z), y) -> copysign(x, y)
150188
define <4 x float> @combine_vec_fcopysign_fcopysign_mag(<4 x float> %x, <4 x float> %y, <4 x float> %z) {
151189
; SSE-LABEL: combine_vec_fcopysign_fcopysign_mag:

test/CodeGen/X86/dag-fmf-cse.ll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ define float @fmf_should_not_break_cse(float %a, float %b) {
1919
ret float %abx2
2020
}
2121

22+
define float @fmf_should_not_break_cse_unary_fneg(float %a, float %b) {
23+
; CHECK-LABEL: fmf_should_not_break_cse_unary_fneg:
24+
; CHECK: # %bb.0:
25+
; CHECK-NEXT: vmulss %xmm1, %xmm0, %xmm0
26+
; CHECK-NEXT: vaddss %xmm0, %xmm0, %xmm0
27+
; CHECK-NEXT: retq
28+
%mul1 = fmul fast float %a, %b
29+
%nega = fneg fast float %a
30+
%mul2 = fmul fast float %nega, %b
31+
%abx2 = fsub fast float %mul1, %mul2
32+
ret float %abx2
33+
}
34+
2235
define <4 x float> @fmf_should_not_break_cse_vector(<4 x float> %a, <4 x float> %b) {
2336
; CHECK-LABEL: fmf_should_not_break_cse_vector:
2437
; CHECK: # %bb.0:
@@ -31,3 +44,16 @@ define <4 x float> @fmf_should_not_break_cse_vector(<4 x float> %a, <4 x float>
3144
%abx2 = fsub fast <4 x float> %mul1, %mul2
3245
ret <4 x float> %abx2
3346
}
47+
48+
define <4 x float> @fmf_should_not_break_cse_vector_unary_fneg(<4 x float> %a, <4 x float> %b) {
49+
; CHECK-LABEL: fmf_should_not_break_cse_vector_unary_fneg:
50+
; CHECK: # %bb.0:
51+
; CHECK-NEXT: vmulps %xmm1, %xmm0, %xmm0
52+
; CHECK-NEXT: vaddps %xmm0, %xmm0, %xmm0
53+
; CHECK-NEXT: retq
54+
%mul1 = fmul fast <4 x float> %a, %b
55+
%nega = fneg fast <4 x float> %a
56+
%mul2 = fmul fast <4 x float> %nega, %b
57+
%abx2 = fsub fast <4 x float> %mul1, %mul2
58+
ret <4 x float> %abx2
59+
}

test/CodeGen/X86/fast-isel-fneg.ll

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ define void @goo(double* %x, double* %y) nounwind {
7474
ret void
7575
}
7676

77+
define void @goo_unary_fneg(double* %x, double* %y) nounwind {
78+
; CHECK-LABEL: goo_unary_fneg:
79+
; CHECK: ## %bb.0:
80+
; CHECK-NEXT: movq {{.*#+}} xmm0 = mem[0],zero
81+
; CHECK-NEXT: movq %xmm0, %rax
82+
; CHECK-NEXT: movabsq $-9223372036854775808, %rcx ## imm = 0x8000000000000000
83+
; CHECK-NEXT: xorq %rax, %rcx
84+
; CHECK-NEXT: movq %rcx, %xmm0
85+
; CHECK-NEXT: movq %xmm0, (%rsi)
86+
; CHECK-NEXT: retq
87+
;
88+
; SSE2-LABEL: goo_unary_fneg:
89+
; SSE2: # %bb.0:
90+
; SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
91+
; SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
92+
; SSE2-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero
93+
; SSE2-NEXT: xorps {{\.LCPI.*}}, %xmm0
94+
; SSE2-NEXT: movsd %xmm0, (%eax)
95+
; SSE2-NEXT: retl
96+
%a = load double, double* %x
97+
%b = fneg double %a
98+
store double %b, double* %y
99+
ret void
100+
}
101+
77102
define void @loo(float* %x, float* %y) nounwind {
78103
; CHECK-LABEL: loo:
79104
; CHECK: ## %bb.0:
@@ -100,6 +125,32 @@ define void @loo(float* %x, float* %y) nounwind {
100125
ret void
101126
}
102127

128+
define void @loo_unary_fneg(float* %x, float* %y) nounwind {
129+
; CHECK-LABEL: loo_unary_fneg:
130+
; CHECK: ## %bb.0:
131+
; CHECK-NEXT: movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
132+
; CHECK-NEXT: movd %xmm0, %eax
133+
; CHECK-NEXT: xorl $2147483648, %eax ## imm = 0x80000000
134+
; CHECK-NEXT: movd %eax, %xmm0
135+
; CHECK-NEXT: movd %xmm0, (%rsi)
136+
; CHECK-NEXT: retq
137+
;
138+
; SSE2-LABEL: loo_unary_fneg:
139+
; SSE2: # %bb.0:
140+
; SSE2-NEXT: movl {{[0-9]+}}(%esp), %eax
141+
; SSE2-NEXT: movl {{[0-9]+}}(%esp), %ecx
142+
; SSE2-NEXT: movd {{.*#+}} xmm0 = mem[0],zero,zero,zero
143+
; SSE2-NEXT: movd %xmm0, %ecx
144+
; SSE2-NEXT: xorl $2147483648, %ecx # imm = 0x80000000
145+
; SSE2-NEXT: movd %ecx, %xmm0
146+
; SSE2-NEXT: movd %xmm0, (%eax)
147+
; SSE2-NEXT: retl
148+
%a = load float, float* %x
149+
%b = fneg float %a
150+
store float %b, float* %y
151+
ret void
152+
}
153+
103154
define double @too(double %x) nounwind {
104155
; CHECK-LABEL: too:
105156
; CHECK: ## %bb.0:

test/CodeGen/X86/fdiv.ll

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,39 @@ define float @double_negative(float %x, float %y) #0 {
6565
ret float %div
6666
}
6767

68+
define float @double_negative_unary_fneg_x_unary_fneg_y(float %x, float %y) #0 {
69+
; CHECK-LABEL: double_negative_unary_fneg_x_unary_fneg_y:
70+
; CHECK: # %bb.0:
71+
; CHECK-NEXT: divss %xmm1, %xmm0
72+
; CHECK-NEXT: retq
73+
%neg1 = fneg float %x
74+
%neg2 = fneg float %y
75+
%div = fdiv float %neg1, %neg2
76+
ret float %div
77+
}
78+
79+
define float @double_negative_unary_fneg_x(float %x, float %y) #0 {
80+
; CHECK-LABEL: double_negative_unary_fneg_x:
81+
; CHECK: # %bb.0:
82+
; CHECK-NEXT: divss %xmm1, %xmm0
83+
; CHECK-NEXT: retq
84+
%neg1 = fneg float %x
85+
%neg2 = fsub float -0.0, %y
86+
%div = fdiv float %neg1, %neg2
87+
ret float %div
88+
}
89+
90+
define float @double_negative_unary_fneg_y(float %x, float %y) #0 {
91+
; CHECK-LABEL: double_negative_unary_fneg_y:
92+
; CHECK: # %bb.0:
93+
; CHECK-NEXT: divss %xmm1, %xmm0
94+
; CHECK-NEXT: retq
95+
%neg1 = fsub float -0.0, %x
96+
%neg2 = fneg float %y
97+
%div = fdiv float %neg1, %neg2
98+
ret float %div
99+
}
100+
68101
define <4 x float> @double_negative_vector(<4 x float> %x, <4 x float> %y) #0 {
69102
; CHECK-LABEL: double_negative_vector:
70103
; CHECK: # %bb.0:
@@ -76,5 +109,38 @@ define <4 x float> @double_negative_vector(<4 x float> %x, <4 x float> %y) #0 {
76109
ret <4 x float> %div
77110
}
78111

112+
define <4 x float> @double_negative_vector_unary_fneg_x_unary_fneg_y(<4 x float> %x, <4 x float> %y) #0 {
113+
; CHECK-LABEL: double_negative_vector_unary_fneg_x_unary_fneg_y:
114+
; CHECK: # %bb.0:
115+
; CHECK-NEXT: divps %xmm1, %xmm0
116+
; CHECK-NEXT: retq
117+
%neg1 = fneg <4 x float> %x
118+
%neg2 = fneg <4 x float> %y
119+
%div = fdiv <4 x float> %neg1, %neg2
120+
ret <4 x float> %div
121+
}
122+
123+
define <4 x float> @double_negative_vector_unary_fneg_x(<4 x float> %x, <4 x float> %y) #0 {
124+
; CHECK-LABEL: double_negative_vector_unary_fneg_x:
125+
; CHECK: # %bb.0:
126+
; CHECK-NEXT: divps %xmm1, %xmm0
127+
; CHECK-NEXT: retq
128+
%neg1 = fneg <4 x float> %x
129+
%neg2 = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %y
130+
%div = fdiv <4 x float> %neg1, %neg2
131+
ret <4 x float> %div
132+
}
133+
134+
define <4 x float> @double_negative_vector_unary_fneg_y(<4 x float> %x, <4 x float> %y) #0 {
135+
; CHECK-LABEL: double_negative_vector_unary_fneg_y:
136+
; CHECK: # %bb.0:
137+
; CHECK-NEXT: divps %xmm1, %xmm0
138+
; CHECK-NEXT: retq
139+
%neg1 = fsub <4 x float> <float -0.0, float -0.0, float -0.0, float -0.0>, %x
140+
%neg2 = fneg <4 x float> %y
141+
%div = fdiv <4 x float> %neg1, %neg2
142+
ret <4 x float> %div
143+
}
144+
79145
attributes #0 = { "unsafe-fp-math"="false" }
80146

0 commit comments

Comments
 (0)