Skip to content

Commit 32b7738

Browse files
committed
[SelectionDAG] Support promotion of the FPOWI integer operand
For targets where i32 is not a legal type (e.g. 64-bit RISC-V), LegalizeIntegerTypes must promote the integer operand of ISD::FPOWI. As this is a signed value, this should be sign-extended. This patch enables all tests in test/CodeGen/RISCVfloat-intrinsics.ll for RV64, as prior to this patch that file couldn't be compiled for RV64 due to an assertion when performing codegen for fpowi. Differential Revision: https://reviews.llvm.org/D54574 llvm-svn: 352832
1 parent 3aba9fd commit 32b7738

File tree

4 files changed

+229
-1
lines changed

4 files changed

+229
-1
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ namespace ISD {
579579
/// is often a storage-only type but has native conversions.
580580
FP16_TO_FP, FP_TO_FP16,
581581

582-
/// Perform various unary floating-point operations inspired by libm.
582+
/// Perform various unary floating-point operations inspired by libm. For
583+
/// FPOWI, the result is undefined if if the integer operand doesn't fit
584+
/// into 32 bits.
583585
FNEG, FABS, FSQRT, FCBRT, FSIN, FCOS, FPOWI, FPOW,
584586
FLOG, FLOG2, FLOG10, FEXP, FEXP2,
585587
FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR,

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,8 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N, unsigned OpNo) {
10911091
case ISD::PREFETCH: Res = PromoteIntOp_PREFETCH(N, OpNo); break;
10921092

10931093
case ISD::SMULFIX: Res = PromoteIntOp_SMULFIX(N); break;
1094+
1095+
case ISD::FPOWI: Res = PromoteIntOp_FPOWI(N); break;
10941096
}
10951097

10961098
// If the result is null, the sub-method took care of registering results etc.
@@ -1474,6 +1476,11 @@ SDValue DAGTypeLegalizer::PromoteIntOp_PREFETCH(SDNode *N, unsigned OpNo) {
14741476
0);
14751477
}
14761478

1479+
SDValue DAGTypeLegalizer::PromoteIntOp_FPOWI(SDNode *N) {
1480+
SDValue Op = SExtPromotedInteger(N->getOperand(1));
1481+
return SDValue(DAG.UpdateNodeOperands(N, N->getOperand(0), Op), 0);
1482+
}
1483+
14771484
//===----------------------------------------------------------------------===//
14781485
// Integer Result Expansion
14791486
//===----------------------------------------------------------------------===//

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
379379
SDValue PromoteIntOp_FRAMERETURNADDR(SDNode *N);
380380
SDValue PromoteIntOp_PREFETCH(SDNode *N, unsigned OpNo);
381381
SDValue PromoteIntOp_SMULFIX(SDNode *N);
382+
SDValue PromoteIntOp_FPOWI(SDNode *N);
382383

383384
void PromoteSetCCOperands(SDValue &LHS,SDValue &RHS, ISD::CondCode Code);
384385

0 commit comments

Comments
 (0)