Skip to content

Commit 1776f6c

Browse files
[RISCV] Fix support for strict version of fp to (u)int and (u)int to fp
1 parent 5c3a0fa commit 1776f6c

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,6 +3090,8 @@ void DAGTypeLegalizer::SoftPromoteHalfResult(SDNode *N, unsigned ResNo) {
30903090
break;
30913091
case ISD::SELECT: R = SoftPromoteHalfRes_SELECT(N); break;
30923092
case ISD::SELECT_CC: R = SoftPromoteHalfRes_SELECT_CC(N); break;
3093+
case ISD::STRICT_SINT_TO_FP:
3094+
case ISD::STRICT_UINT_TO_FP:
30933095
case ISD::SINT_TO_FP:
30943096
case ISD::UINT_TO_FP: R = SoftPromoteHalfRes_XINT_TO_FP(N); break;
30953097
case ISD::UNDEF: R = SoftPromoteHalfRes_UNDEF(N); break;
@@ -3311,8 +3313,17 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfRes_XINT_TO_FP(SDNode *N) {
33113313
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), OVT);
33123314
SDLoc dl(N);
33133315

3314-
SDValue Res = DAG.getNode(N->getOpcode(), dl, NVT, N->getOperand(0));
3316+
if (N->isStrictFPOpcode()) {
3317+
SDValue Chain = N->getOperand(0);
3318+
SDValue Res =
3319+
DAG.getNode(N->getOpcode(), dl, {NVT, MVT::Other}, {Chain, N->getOperand(1)});
33153320

3321+
ReplaceValueWith(SDValue(N, 1), Res);
3322+
// Round the value to the softened type.
3323+
return DAG.getNode(GetPromotionOpcode(NVT, OVT), dl, MVT::i16, Res);
3324+
}
3325+
3326+
SDValue Res = DAG.getNode(N->getOpcode(), dl, NVT, N->getOperand(0));
33163327
// Round the value to the softened type.
33173328
return DAG.getNode(GetPromotionOpcode(NVT, OVT), dl, MVT::i16, Res);
33183329
}
@@ -3396,6 +3407,8 @@ bool DAGTypeLegalizer::SoftPromoteHalfOperand(SDNode *N, unsigned OpNo) {
33963407

33973408
case ISD::BITCAST: Res = SoftPromoteHalfOp_BITCAST(N); break;
33983409
case ISD::FCOPYSIGN: Res = SoftPromoteHalfOp_FCOPYSIGN(N, OpNo); break;
3410+
case ISD::STRICT_FP_TO_SINT:
3411+
case ISD::STRICT_FP_TO_UINT:
33993412
case ISD::FP_TO_SINT:
34003413
case ISD::FP_TO_UINT: Res = SoftPromoteHalfOp_FP_TO_XINT(N); break;
34013414
case ISD::FP_TO_SINT_SAT:
@@ -3422,7 +3435,7 @@ bool DAGTypeLegalizer::SoftPromoteHalfOperand(SDNode *N, unsigned OpNo) {
34223435

34233436
assert(Res.getNode() != N && "Expected a new node!");
34243437

3425-
assert(Res.getValueType() == N->getValueType(0) && N->getNumValues() == 1 &&
3438+
assert(Res.getValueType() == N->getValueType(0) &&
34263439
"Invalid operand expansion");
34273440

34283441
ReplaceValueWith(SDValue(N, 0), Res);
@@ -3451,6 +3464,7 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FCOPYSIGN(SDNode *N,
34513464
Op1);
34523465
}
34533466

3467+
34543468
SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_EXTEND(SDNode *N) {
34553469
EVT RVT = N->getValueType(0);
34563470
bool IsStrict = N->isStrictFPOpcode();
@@ -3479,16 +3493,22 @@ SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_EXTEND(SDNode *N) {
34793493

34803494
SDValue DAGTypeLegalizer::SoftPromoteHalfOp_FP_TO_XINT(SDNode *N) {
34813495
EVT RVT = N->getValueType(0);
3482-
SDValue Op = N->getOperand(0);
3496+
SDValue Op = N->getOperand(N->isStrictFPOpcode() ? 1 : 0);
34833497
EVT SVT = Op.getValueType();
34843498
SDLoc dl(N);
34853499

34863500
EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), Op.getValueType());
34873501

34883502
Op = GetSoftPromotedHalf(Op);
34893503

3490-
SDValue Res = DAG.getNode(GetPromotionOpcode(SVT, RVT), dl, NVT, Op);
3504+
if (N->isStrictFPOpcode()) {
3505+
SDValue Res = DAG.getNode(GetPromotionOpcode(SVT, RVT), dl, NVT, Op);
3506+
// ReplaceValueWith(SDValue(N, 1), Res);
3507+
SDValue Chain = N->getOperand(0);
3508+
return DAG.getNode(N->getOpcode(), dl, N->getValueType(0), { Chain, Res });
3509+
}
34913510

3511+
SDValue Res = DAG.getNode(GetPromotionOpcode(SVT, RVT), dl, NVT, Op);
34923512
return DAG.getNode(N->getOpcode(), dl, N->getValueType(0), Res);
34933513
}
34943514

llvm/test/CodeGen/RISCV/half-convert-strict.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
; RUN: llc -mtriple=riscv64 -mattr=+zdinx,+zhinxmin -verify-machineinstrs \
4848
; RUN: -target-abi lp64 -disable-strictnode-mutation < %s \
4949
; RUN: | FileCheck -check-prefixes=CHECK64-IZDINXZHINXMIN %s
50+
; RUN: llc -mtriple=riscv32 -mattr=+d -verify-machineinstrs \
51+
; RUN: -target-abi ilp32d -disable-strictnode-mutation < %s \
52+
; RUN: | FileCheck -check-prefixes=CHECKD,RV32D %s
5053

5154
; NOTE: The rounding mode metadata does not effect which instruction is
5255
; selected. Dynamic rounding mode is always used for operations that

0 commit comments

Comments
 (0)