Skip to content

Commit ea4e19d

Browse files
authored
[SDAG] Add missing ppc_fp128 ExpandFloatRes for sincos[pi] (#128514)
1 parent 5114b9b commit ea4e19d

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,8 @@ void DAGTypeLegalizer::ExpandFloatResult(SDNode *N, unsigned ResNo) {
15701570
case ISD::STRICT_FREM:
15711571
case ISD::FREM: ExpandFloatRes_FREM(N, Lo, Hi); break;
15721572
case ISD::FMODF: ExpandFloatRes_FMODF(N); break;
1573+
case ISD::FSINCOS: ExpandFloatRes_FSINCOS(N); break;
1574+
case ISD::FSINCOSPI: ExpandFloatRes_FSINCOSPI(N); break;
15731575
// clang-format on
15741576
}
15751577

@@ -1625,6 +1627,15 @@ void DAGTypeLegalizer::ExpandFloatRes_FMODF(SDNode *N) {
16251627
/*CallRetResNo=*/0);
16261628
}
16271629

1630+
void DAGTypeLegalizer::ExpandFloatRes_FSINCOS(SDNode *N) {
1631+
ExpandFloatRes_UnaryWithTwoFPResults(N, RTLIB::getSINCOS(N->getValueType(0)));
1632+
}
1633+
1634+
void DAGTypeLegalizer::ExpandFloatRes_FSINCOSPI(SDNode *N) {
1635+
ExpandFloatRes_UnaryWithTwoFPResults(N,
1636+
RTLIB::getSINCOSPI(N->getValueType(0)));
1637+
}
1638+
16281639
void DAGTypeLegalizer::ExpandFloatRes_UnaryWithTwoFPResults(
16291640
SDNode *N, RTLIB::Libcall LC, std::optional<unsigned> CallRetResNo) {
16301641
assert(!N->isStrictFPOpcode() && "strictfp not implemented");

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
718718
void ExpandFloatRes_LOAD (SDNode *N, SDValue &Lo, SDValue &Hi);
719719
void ExpandFloatRes_XINT_TO_FP(SDNode *N, SDValue &Lo, SDValue &Hi);
720720
void ExpandFloatRes_FMODF(SDNode *N);
721+
void ExpandFloatRes_FSINCOS(SDNode* N);
722+
void ExpandFloatRes_FSINCOSPI(SDNode* N);
721723
// clang-format on
722724

723725
// Float Operand Expansion.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2+
; RUN: llc -mcpu=pwr9 -mtriple=powerpc64le-gnu-linux \
3+
; RUN: -ppc-vsr-nums-as-vr -ppc-asm-full-reg-names < %s | FileCheck %s
4+
5+
define { ppc_fp128, ppc_fp128 } @test_sincos_ppcf128(ppc_fp128 %a) {
6+
; CHECK-LABEL: test_sincos_ppcf128:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: mflr r0
9+
; CHECK-NEXT: stdu r1, -64(r1)
10+
; CHECK-NEXT: std r0, 80(r1)
11+
; CHECK-NEXT: .cfi_def_cfa_offset 64
12+
; CHECK-NEXT: .cfi_offset lr, 16
13+
; CHECK-NEXT: addi r5, r1, 48
14+
; CHECK-NEXT: addi r6, r1, 32
15+
; CHECK-NEXT: bl sincosl
16+
; CHECK-NEXT: nop
17+
; CHECK-NEXT: lfd f1, 48(r1)
18+
; CHECK-NEXT: lfd f2, 56(r1)
19+
; CHECK-NEXT: lfd f3, 32(r1)
20+
; CHECK-NEXT: lfd f4, 40(r1)
21+
; CHECK-NEXT: addi r1, r1, 64
22+
; CHECK-NEXT: ld r0, 16(r1)
23+
; CHECK-NEXT: mtlr r0
24+
; CHECK-NEXT: blr
25+
%result = call { ppc_fp128, ppc_fp128 } @llvm.sincos.ppcf128(ppc_fp128 %a)
26+
ret { ppc_fp128, ppc_fp128 } %result
27+
}
28+
29+
define { ppc_fp128, ppc_fp128 } @test_sincospi_ppcf128(ppc_fp128 %a) {
30+
; CHECK-LABEL: test_sincospi_ppcf128:
31+
; CHECK: # %bb.0:
32+
; CHECK-NEXT: mflr r0
33+
; CHECK-NEXT: stdu r1, -64(r1)
34+
; CHECK-NEXT: std r0, 80(r1)
35+
; CHECK-NEXT: .cfi_def_cfa_offset 64
36+
; CHECK-NEXT: .cfi_offset lr, 16
37+
; CHECK-NEXT: addi r5, r1, 48
38+
; CHECK-NEXT: addi r6, r1, 32
39+
; CHECK-NEXT: bl sincospil
40+
; CHECK-NEXT: nop
41+
; CHECK-NEXT: lfd f1, 48(r1)
42+
; CHECK-NEXT: lfd f2, 56(r1)
43+
; CHECK-NEXT: lfd f3, 32(r1)
44+
; CHECK-NEXT: lfd f4, 40(r1)
45+
; CHECK-NEXT: addi r1, r1, 64
46+
; CHECK-NEXT: ld r0, 16(r1)
47+
; CHECK-NEXT: mtlr r0
48+
; CHECK-NEXT: blr
49+
%result = call { ppc_fp128, ppc_fp128 } @llvm.sincospi.ppcf128(ppc_fp128 %a)
50+
ret { ppc_fp128, ppc_fp128 } %result
51+
}
52+
53+
; FIXME: This could be made a tail call with the default expansion of llvm.sincos.
54+
define void @test_sincos_ppcf128_void_tail_call(ppc_fp128 %a, ptr noalias %out_sin, ptr noalias %out_cos) {
55+
; CHECK-LABEL: test_sincos_ppcf128_void_tail_call:
56+
; CHECK: # %bb.0:
57+
; CHECK-NEXT: mflr r0
58+
; CHECK-NEXT: stdu r1, -32(r1)
59+
; CHECK-NEXT: std r0, 48(r1)
60+
; CHECK-NEXT: .cfi_def_cfa_offset 32
61+
; CHECK-NEXT: .cfi_offset lr, 16
62+
; CHECK-NEXT: bl sincosl
63+
; CHECK-NEXT: nop
64+
; CHECK-NEXT: addi r1, r1, 32
65+
; CHECK-NEXT: ld r0, 16(r1)
66+
; CHECK-NEXT: mtlr r0
67+
; CHECK-NEXT: blr
68+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.sincos.ppcf128(ppc_fp128 %a)
69+
%result.0 = extractvalue { ppc_fp128, ppc_fp128 } %result, 0
70+
%result.1 = extractvalue { ppc_fp128, ppc_fp128 } %result, 1
71+
store ppc_fp128 %result.0, ptr %out_sin, align 16
72+
store ppc_fp128 %result.1, ptr %out_cos, align 16
73+
ret void
74+
}
75+
76+
; FIXME: This could be made a tail call with the default expansion of llvm.sincospi.
77+
define void @test_sincospi_ppcf128_void_tail_call(ppc_fp128 %a, ptr noalias %out_sin, ptr noalias %out_cos) {
78+
; CHECK-LABEL: test_sincospi_ppcf128_void_tail_call:
79+
; CHECK: # %bb.0:
80+
; CHECK-NEXT: mflr r0
81+
; CHECK-NEXT: stdu r1, -32(r1)
82+
; CHECK-NEXT: std r0, 48(r1)
83+
; CHECK-NEXT: .cfi_def_cfa_offset 32
84+
; CHECK-NEXT: .cfi_offset lr, 16
85+
; CHECK-NEXT: bl sincospil
86+
; CHECK-NEXT: nop
87+
; CHECK-NEXT: addi r1, r1, 32
88+
; CHECK-NEXT: ld r0, 16(r1)
89+
; CHECK-NEXT: mtlr r0
90+
; CHECK-NEXT: blr
91+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.sincospi.ppcf128(ppc_fp128 %a)
92+
%result.0 = extractvalue { ppc_fp128, ppc_fp128 } %result, 0
93+
%result.1 = extractvalue { ppc_fp128, ppc_fp128 } %result, 1
94+
store ppc_fp128 %result.0, ptr %out_sin, align 16
95+
store ppc_fp128 %result.1, ptr %out_cos, align 16
96+
ret void
97+
}
98+
99+
; NOTE: This would need a struct-return library call for llvm.sincos to become a tail call.
100+
define { ppc_fp128, ppc_fp128 } @test_sincos_ppcf128_tail_call(ppc_fp128 %a) {
101+
; CHECK-LABEL: test_sincos_ppcf128_tail_call:
102+
; CHECK: # %bb.0:
103+
; CHECK-NEXT: mflr r0
104+
; CHECK-NEXT: stdu r1, -64(r1)
105+
; CHECK-NEXT: std r0, 80(r1)
106+
; CHECK-NEXT: .cfi_def_cfa_offset 64
107+
; CHECK-NEXT: .cfi_offset lr, 16
108+
; CHECK-NEXT: addi r5, r1, 48
109+
; CHECK-NEXT: addi r6, r1, 32
110+
; CHECK-NEXT: bl sincosl
111+
; CHECK-NEXT: nop
112+
; CHECK-NEXT: lfd f1, 48(r1)
113+
; CHECK-NEXT: lfd f2, 56(r1)
114+
; CHECK-NEXT: lfd f3, 32(r1)
115+
; CHECK-NEXT: lfd f4, 40(r1)
116+
; CHECK-NEXT: addi r1, r1, 64
117+
; CHECK-NEXT: ld r0, 16(r1)
118+
; CHECK-NEXT: mtlr r0
119+
; CHECK-NEXT: blr
120+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.sincos.ppcf128(ppc_fp128 %a)
121+
ret { ppc_fp128, ppc_fp128 } %result
122+
}
123+
124+
; NOTE: This would need a struct-return library call for llvm.sincospi to become a tail call.
125+
define { ppc_fp128, ppc_fp128 } @test_sincospi_ppcf128_tail_call(ppc_fp128 %a) {
126+
; CHECK-LABEL: test_sincospi_ppcf128_tail_call:
127+
; CHECK: # %bb.0:
128+
; CHECK-NEXT: mflr r0
129+
; CHECK-NEXT: stdu r1, -64(r1)
130+
; CHECK-NEXT: std r0, 80(r1)
131+
; CHECK-NEXT: .cfi_def_cfa_offset 64
132+
; CHECK-NEXT: .cfi_offset lr, 16
133+
; CHECK-NEXT: addi r5, r1, 48
134+
; CHECK-NEXT: addi r6, r1, 32
135+
; CHECK-NEXT: bl sincospil
136+
; CHECK-NEXT: nop
137+
; CHECK-NEXT: lfd f1, 48(r1)
138+
; CHECK-NEXT: lfd f2, 56(r1)
139+
; CHECK-NEXT: lfd f3, 32(r1)
140+
; CHECK-NEXT: lfd f4, 40(r1)
141+
; CHECK-NEXT: addi r1, r1, 64
142+
; CHECK-NEXT: ld r0, 16(r1)
143+
; CHECK-NEXT: mtlr r0
144+
; CHECK-NEXT: blr
145+
%result = tail call { ppc_fp128, ppc_fp128 } @llvm.sincospi.ppcf128(ppc_fp128 %a)
146+
ret { ppc_fp128, ppc_fp128 } %result
147+
}

0 commit comments

Comments
 (0)