• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: llc < %s -mtriple=ve | FileCheck %s
2
3;;; Test ‘llvm.copysign.*’ Intrinsic
4;;;
5;;; Syntax:
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.
9;;;
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)
15;;;
16;;; Overview:
17;;;   The ‘llvm.copysign.*’ intrinsics return a value with the magnitude of
18;;;   the first operand and the sign of the second operand.
19;;;
20;;; Arguments:
21;;;   The arguments and return value are floating-point numbers of the same
22;;;   type.
23;;;
24;;; Semantics:
25;;;   This function returns the same values as the libm copysign functions
26;;;   would, and handles error conditions in the same way.
27;;;
28;;; Note:
29;;;   We test only float/double/fp128.
30
31; Function Attrs: nounwind readnone
32define float @copysign_float_var(float %0, float %1) {
33; CHECK-LABEL: copysign_float_var:
34; CHECK:       # %bb.0:
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)
45  ret float %3
46}
47
48; Function Attrs: nounwind readnone speculatable willreturn
49declare float @llvm.copysign.f32(float, float)
50
51; Function Attrs: nounwind readnone
52define double @copysign_double_var(double %0, double %1) {
53; CHECK-LABEL: copysign_double_var:
54; CHECK:       # %bb.0:
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)
60  ret double %3
61}
62
63; Function Attrs: nounwind readnone speculatable willreturn
64declare double @llvm.copysign.f64(double, double)
65
66; Function Attrs: nounwind readnone
67define 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)
86  ret fp128 %3
87}
88
89; Function Attrs: nounwind readnone speculatable willreturn
90declare fp128 @llvm.copysign.f128(fp128, fp128)
91
92; Function Attrs: nounwind readnone
93define float @copysign_float_zero(float %0) {
94; CHECK-LABEL: copysign_float_zero:
95; CHECK:       # %bb.0:
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)
103  ret float %2
104}
105
106; Function Attrs: nounwind readnone
107define double @copysign_double_zero(double %0) {
108; CHECK-LABEL: copysign_double_zero:
109; CHECK:       # %bb.0:
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)
113  ret double %2
114}
115
116; Function Attrs: nounwind readnone
117define 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)
141  ret fp128 %2
142}
143
144; Function Attrs: nounwind readnone
145define float @copysign_float_const(float %0) {
146; CHECK-LABEL: copysign_float_const:
147; CHECK:       # %bb.0:
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)
157  ret float %2
158}
159
160; Function Attrs: nounwind readnone
161define double @copysign_double_const(double %0) {
162; CHECK-LABEL: copysign_double_const:
163; CHECK:       # %bb.0:
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)
169  ret double %2
170}
171
172; Function Attrs: nounwind readnone
173define 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)
197  ret fp128 %2
198}
199