Skip to content

Commit 2ea8f20

Browse files
committed
[CodeGen] Fix ConvertNodeToLibcall for STRICT_FPOWI
Reviewed By: PengfeiWang Differential Revision: https://reviews.llvm.org/D125159
1 parent 8bef547 commit 2ea8f20

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,12 +4098,25 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
40984098
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpected fpowi.");
40994099
if (!TLI.getLibcallName(LC)) {
41004100
// Some targets don't have a powi libcall; use pow instead.
4101-
SDValue Exponent = DAG.getNode(ISD::SINT_TO_FP, SDLoc(Node),
4102-
Node->getValueType(0),
4103-
Node->getOperand(1));
4104-
Results.push_back(DAG.getNode(ISD::FPOW, SDLoc(Node),
4105-
Node->getValueType(0), Node->getOperand(0),
4106-
Exponent));
4101+
if (Node->isStrictFPOpcode()) {
4102+
SDValue Exponent =
4103+
DAG.getNode(ISD::STRICT_SINT_TO_FP, SDLoc(Node),
4104+
{Node->getValueType(0), Node->getValueType(1)},
4105+
{Node->getOperand(0), Node->getOperand(2)});
4106+
SDValue FPOW =
4107+
DAG.getNode(ISD::STRICT_FPOW, SDLoc(Node),
4108+
{Node->getValueType(0), Node->getValueType(1)},
4109+
{Exponent.getValue(1), Node->getOperand(1), Exponent});
4110+
Results.push_back(FPOW);
4111+
Results.push_back(FPOW.getValue(1));
4112+
} else {
4113+
SDValue Exponent =
4114+
DAG.getNode(ISD::SINT_TO_FP, SDLoc(Node), Node->getValueType(0),
4115+
Node->getOperand(1));
4116+
Results.push_back(DAG.getNode(ISD::FPOW, SDLoc(Node),
4117+
Node->getValueType(0),
4118+
Node->getOperand(0), Exponent));
4119+
}
41074120
break;
41084121
}
41094122
unsigned Offset = Node->isStrictFPOpcode() ? 1 : 0;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=x86_64-pc-windows-msvc %s -o - | FileCheck %s -check-prefix=WIN
3+
; RUN: llc -mtriple=x86_64-pc-linux %s -o -| FileCheck %s -check-prefix=UNIX
4+
5+
declare float @llvm.experimental.constrained.powi.f32.i32(float, i32, metadata, metadata)
6+
7+
define float @powi_f64(float %a, i32 %b) nounwind strictfp {
8+
; WIN-LABEL: powi_f64:
9+
; WIN: # %bb.0:
10+
; WIN-NEXT: subq $40, %rsp
11+
; WIN-NEXT: cvtsi2ss %edx, %xmm1
12+
; WIN-NEXT: callq powf
13+
; WIN-NEXT: addq $40, %rsp
14+
; WIN-NEXT: retq
15+
;
16+
; UNIX-LABEL: powi_f64:
17+
; UNIX: # %bb.0:
18+
; UNIX-NEXT: pushq %rax
19+
; UNIX-NEXT: callq __powisf2@PLT
20+
; UNIX-NEXT: popq %rax
21+
; UNIX-NEXT: retq
22+
%1 = call float @llvm.experimental.constrained.powi.f32.i32(float %a, i32 %b, metadata !"round.tonearest", metadata !"fpexcept.ignore") strictfp
23+
ret float %1
24+
}

0 commit comments

Comments
 (0)