1 ; RUN: llc < %s -mtriple=ve | FileCheck %s
3 ;;; Test ‘llvm.copysign.*’ Intrinsic
6 ;;; This is an overloaded intrinsic. You can use llvm.copysign on any
7 ;;; floating-point or vector of floating-point type. Not all targets
8 ;;; support all types however.
10 ;;; declare float @llvm.copysign.f32(float %Mag, float %Sgn)
11 ;;; declare double @llvm.copysign.f64(double %Mag, double %Sgn)
12 ;;; declare x86_fp80 @llvm.copysign.f80(x86_fp80 %Mag, x86_fp80 %Sgn)
13 ;;; declare fp128 @llvm.copysign.f128(fp128 %Mag, fp128 %Sgn)
14 ;;; declare ppc_fp128 @llvm.copysign.ppcf128(ppc_fp128 %Mag, ppc_fp128 %Sgn)
17 ;;; The ‘llvm.copysign.*’ intrinsics return a value with the magnitude of
18 ;;; the first operand and the sign of the second operand.
21 ;;; The arguments and return value are floating-point numbers of the same
25 ;;; This function returns the same values as the libm copysign functions
26 ;;; would, and handles error conditions in the same way.
29 ;;; We test only float/double/fp128.
31 ; Function Attrs: nounwind readnone
32 define float @copysign_float_var(float %0, float %1) {
33 ; CHECK-LABEL: copysign_float_var:
35 ; CHECK-NEXT: sra.l %s1, %s1, 32
36 ; CHECK-NEXT: lea %s2, -2147483648
37 ; CHECK-NEXT: and %s2, %s2, (32)0
38 ; CHECK-NEXT: and %s1, %s1, %s2
39 ; CHECK-NEXT: sra.l %s0, %s0, 32
40 ; CHECK-NEXT: and %s0, %s0, (33)0
41 ; CHECK-NEXT: or %s0, %s0, %s1
42 ; CHECK-NEXT: sll %s0, %s0, 32
43 ; CHECK-NEXT: b.l.t (, %s10)
44 %3 = tail call fast float @llvm.copysign.f32(float %0, float %1)
48 ; Function Attrs: nounwind readnone speculatable willreturn
49 declare float @llvm.copysign.f32(float, float)
51 ; Function Attrs: nounwind readnone
52 define double @copysign_double_var(double %0, double %1) {
53 ; CHECK-LABEL: copysign_double_var:
55 ; CHECK-NEXT: and %s1, %s1, (1)1
56 ; CHECK-NEXT: and %s0, %s0, (1)0
57 ; CHECK-NEXT: or %s0, %s0, %s1
58 ; CHECK-NEXT: b.l.t (, %s10)
59 %3 = tail call fast double @llvm.copysign.f64(double %0, double %1)
63 ; Function Attrs: nounwind readnone speculatable willreturn
64 declare double @llvm.copysign.f64(double, double)
66 ; Function Attrs: nounwind readnone
67 define fp128 @copysign_quad_var(fp128 %0, fp128 %1) {
68 ; CHECK-LABEL: copysign_quad_var:
69 ; CHECK: .LBB{{[0-9]+}}_2:
70 ; CHECK-NEXT: st %s3, 16(, %s11)
71 ; CHECK-NEXT: st %s2, 24(, %s11)
72 ; CHECK-NEXT: st %s1, (, %s11)
73 ; CHECK-NEXT: st %s0, 8(, %s11)
74 ; CHECK-NEXT: ld1b.zx %s0, 31(, %s11)
75 ; CHECK-NEXT: ld1b.zx %s1, 15(, %s11)
76 ; CHECK-NEXT: lea %s2, 128
77 ; CHECK-NEXT: and %s0, %s0, %s2
78 ; CHECK-NEXT: and %s1, %s1, (57)0
79 ; CHECK-NEXT: or %s0, %s1, %s0
80 ; CHECK-NEXT: st1b %s0, 15(, %s11)
81 ; CHECK-NEXT: ld %s1, (, %s11)
82 ; CHECK-NEXT: ld %s0, 8(, %s11)
83 ; CHECK-NEXT: adds.l %s11, 32, %s11
84 ; CHECK-NEXT: b.l.t (, %s10)
85 %3 = tail call fast fp128 @llvm.copysign.f128(fp128 %0, fp128 %1)
89 ; Function Attrs: nounwind readnone speculatable willreturn
90 declare fp128 @llvm.copysign.f128(fp128, fp128)
92 ; Function Attrs: nounwind readnone
93 define float @copysign_float_zero(float %0) {
94 ; CHECK-LABEL: copysign_float_zero:
96 ; CHECK-NEXT: sra.l %s0, %s0, 32
97 ; CHECK-NEXT: lea %s1, -2147483648
98 ; CHECK-NEXT: and %s1, %s1, (32)0
99 ; CHECK-NEXT: and %s0, %s0, %s1
100 ; CHECK-NEXT: sll %s0, %s0, 32
101 ; CHECK-NEXT: b.l.t (, %s10)
102 %2 = tail call fast float @llvm.copysign.f32(float 0.000000e+00, float %0)
106 ; Function Attrs: nounwind readnone
107 define double @copysign_double_zero(double %0) {
108 ; CHECK-LABEL: copysign_double_zero:
110 ; CHECK-NEXT: and %s0, %s0, (1)1
111 ; CHECK-NEXT: b.l.t (, %s10)
112 %2 = tail call fast double @llvm.copysign.f64(double 0.000000e+00, double %0)
116 ; Function Attrs: nounwind readnone
117 define fp128 @copysign_quad_zero(fp128 %0) {
118 ; CHECK-LABEL: copysign_quad_zero:
119 ; CHECK: .LBB{{[0-9]+}}_2:
120 ; CHECK-NEXT: lea %s2, .LCPI{{[0-9]+}}_0@lo
121 ; CHECK-NEXT: and %s2, %s2, (32)0
122 ; CHECK-NEXT: lea.sl %s2, .LCPI{{[0-9]+}}_0@hi(, %s2)
123 ; CHECK-NEXT: ld %s4, 8(, %s2)
124 ; CHECK-NEXT: ld %s5, (, %s2)
125 ; CHECK-NEXT: st %s1, 16(, %s11)
126 ; CHECK-NEXT: st %s0, 24(, %s11)
127 ; CHECK-NEXT: st %s5, (, %s11)
128 ; CHECK-NEXT: st %s4, 8(, %s11)
129 ; CHECK-NEXT: ld1b.zx %s0, 31(, %s11)
130 ; CHECK-NEXT: ld1b.zx %s1, 15(, %s11)
131 ; CHECK-NEXT: lea %s2, 128
132 ; CHECK-NEXT: and %s0, %s0, %s2
133 ; CHECK-NEXT: and %s1, %s1, (57)0
134 ; CHECK-NEXT: or %s0, %s1, %s0
135 ; CHECK-NEXT: st1b %s0, 15(, %s11)
136 ; CHECK-NEXT: ld %s1, (, %s11)
137 ; CHECK-NEXT: ld %s0, 8(, %s11)
138 ; CHECK-NEXT: adds.l %s11, 32, %s11
139 ; CHECK-NEXT: b.l.t (, %s10)
140 %2 = tail call fast fp128 @llvm.copysign.f128(fp128 0xL00000000000000000000000000000000, fp128 %0)
144 ; Function Attrs: nounwind readnone
145 define float @copysign_float_const(float %0) {
146 ; CHECK-LABEL: copysign_float_const:
148 ; CHECK-NEXT: sra.l %s0, %s0, 32
149 ; CHECK-NEXT: lea %s1, -2147483648
150 ; CHECK-NEXT: and %s1, %s1, (32)0
151 ; CHECK-NEXT: and %s0, %s0, %s1
152 ; CHECK-NEXT: lea %s1, 1073741824
153 ; CHECK-NEXT: or %s0, %s0, %s1
154 ; CHECK-NEXT: sll %s0, %s0, 32
155 ; CHECK-NEXT: b.l.t (, %s10)
156 %2 = tail call fast float @llvm.copysign.f32(float -2.000000e+00, float %0)
160 ; Function Attrs: nounwind readnone
161 define double @copysign_double_const(double %0) {
162 ; CHECK-LABEL: copysign_double_const:
164 ; CHECK-NEXT: and %s0, %s0, (1)1
165 ; CHECK-NEXT: lea.sl %s1, 1073741824
166 ; CHECK-NEXT: or %s0, %s0, %s1
167 ; CHECK-NEXT: b.l.t (, %s10)
168 %2 = tail call fast double @llvm.copysign.f64(double -2.000000e+00, double %0)
172 ; Function Attrs: nounwind readnone
173 define fp128 @copysign_quad_const(fp128 %0) {
174 ; CHECK-LABEL: copysign_quad_const:
175 ; CHECK: .LBB{{[0-9]+}}_2:
176 ; CHECK-NEXT: lea %s2, .LCPI{{[0-9]+}}_0@lo
177 ; CHECK-NEXT: and %s2, %s2, (32)0
178 ; CHECK-NEXT: lea.sl %s2, .LCPI{{[0-9]+}}_0@hi(, %s2)
179 ; CHECK-NEXT: ld %s4, 8(, %s2)
180 ; CHECK-NEXT: ld %s5, (, %s2)
181 ; CHECK-NEXT: st %s1, 16(, %s11)
182 ; CHECK-NEXT: st %s0, 24(, %s11)
183 ; CHECK-NEXT: st %s5, (, %s11)
184 ; CHECK-NEXT: st %s4, 8(, %s11)
185 ; CHECK-NEXT: ld1b.zx %s0, 31(, %s11)
186 ; CHECK-NEXT: ld1b.zx %s1, 15(, %s11)
187 ; CHECK-NEXT: lea %s2, 128
188 ; CHECK-NEXT: and %s0, %s0, %s2
189 ; CHECK-NEXT: and %s1, %s1, (57)0
190 ; CHECK-NEXT: or %s0, %s1, %s0
191 ; CHECK-NEXT: st1b %s0, 15(, %s11)
192 ; CHECK-NEXT: ld %s1, (, %s11)
193 ; CHECK-NEXT: ld %s0, 8(, %s11)
194 ; CHECK-NEXT: adds.l %s11, 32, %s11
195 ; CHECK-NEXT: b.l.t (, %s10)
196 %2 = tail call fast fp128 @llvm.copysign.f128(fp128 0xL0000000000000000C000000000000000, fp128 %0)