Skip to content

Commit 6725a6b

Browse files
committed
[LegalizeTypes][NFC] Combine ExpandIntOp_{S,U}INT_TO_FP to ExpandIntOp_XINT_TO_FP
As with D157399 we can reduce duplication by doing this. Unlike that patch, I'm posting the refactoring before the functional changes I want to make here. Differential Revision: https://reviews.llvm.org/D157403
1 parent 546c3c9 commit 6725a6b

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,11 +5096,11 @@ bool DAGTypeLegalizer::ExpandIntegerOperand(SDNode *N, unsigned OpNo) {
50965096
case ISD::SETCC: Res = ExpandIntOp_SETCC(N); break;
50975097
case ISD::SETCCCARRY: Res = ExpandIntOp_SETCCCARRY(N); break;
50985098
case ISD::STRICT_SINT_TO_FP:
5099-
case ISD::SINT_TO_FP: Res = ExpandIntOp_SINT_TO_FP(N); break;
5099+
case ISD::SINT_TO_FP:
5100+
case ISD::STRICT_UINT_TO_FP:
5101+
case ISD::UINT_TO_FP: Res = ExpandIntOp_XINT_TO_FP(N); break;
51005102
case ISD::STORE: Res = ExpandIntOp_STORE(cast<StoreSDNode>(N), OpNo); break;
51015103
case ISD::TRUNCATE: Res = ExpandIntOp_TRUNCATE(N); break;
5102-
case ISD::STRICT_UINT_TO_FP:
5103-
case ISD::UINT_TO_FP: Res = ExpandIntOp_UINT_TO_FP(N); break;
51045104

51055105
case ISD::SHL:
51065106
case ISD::SRA:
@@ -5385,14 +5385,17 @@ SDValue DAGTypeLegalizer::ExpandIntOp_RETURNADDR(SDNode *N) {
53855385
return SDValue(DAG.UpdateNodeOperands(N, Lo), 0);
53865386
}
53875387

5388-
SDValue DAGTypeLegalizer::ExpandIntOp_SINT_TO_FP(SDNode *N) {
5388+
SDValue DAGTypeLegalizer::ExpandIntOp_XINT_TO_FP(SDNode *N) {
53895389
bool IsStrict = N->isStrictFPOpcode();
5390+
bool IsSigned = N->getOpcode() == ISD::SINT_TO_FP ||
5391+
N->getOpcode() == ISD::STRICT_SINT_TO_FP;
53905392
SDValue Chain = IsStrict ? N->getOperand(0) : SDValue();
53915393
SDValue Op = N->getOperand(IsStrict ? 1 : 0);
53925394
EVT DstVT = N->getValueType(0);
5393-
RTLIB::Libcall LC = RTLIB::getSINTTOFP(Op.getValueType(), DstVT);
5395+
RTLIB::Libcall LC = IsSigned ? RTLIB::getSINTTOFP(Op.getValueType(), DstVT)
5396+
: RTLIB::getUINTTOFP(Op.getValueType(), DstVT);
53945397
assert(LC != RTLIB::UNKNOWN_LIBCALL &&
5395-
"Don't know how to expand this SINT_TO_FP!");
5398+
"Don't know how to expand this XINT_TO_FP!");
53965399
TargetLowering::MakeLibCallOptions CallOptions;
53975400
CallOptions.setSExt(true);
53985401
std::pair<SDValue, SDValue> Tmp =
@@ -5505,27 +5508,6 @@ SDValue DAGTypeLegalizer::ExpandIntOp_TRUNCATE(SDNode *N) {
55055508
return DAG.getNode(ISD::TRUNCATE, SDLoc(N), N->getValueType(0), InL);
55065509
}
55075510

5508-
SDValue DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDNode *N) {
5509-
bool IsStrict = N->isStrictFPOpcode();
5510-
SDValue Chain = IsStrict ? N->getOperand(0) : SDValue();
5511-
SDValue Op = N->getOperand(IsStrict ? 1 : 0);
5512-
EVT DstVT = N->getValueType(0);
5513-
RTLIB::Libcall LC = RTLIB::getUINTTOFP(Op.getValueType(), DstVT);
5514-
assert(LC != RTLIB::UNKNOWN_LIBCALL &&
5515-
"Don't know how to expand this UINT_TO_FP!");
5516-
TargetLowering::MakeLibCallOptions CallOptions;
5517-
CallOptions.setSExt(true);
5518-
std::pair<SDValue, SDValue> Tmp =
5519-
TLI.makeLibCall(DAG, LC, DstVT, Op, CallOptions, SDLoc(N), Chain);
5520-
5521-
if (!IsStrict)
5522-
return Tmp.first;
5523-
5524-
ReplaceValueWith(SDValue(N, 1), Tmp.second);
5525-
ReplaceValueWith(SDValue(N, 0), Tmp.first);
5526-
return SDValue();
5527-
}
5528-
55295511
SDValue DAGTypeLegalizer::ExpandIntOp_ATOMIC_STORE(SDNode *N) {
55305512
SDLoc dl(N);
55315513
SDValue Swap = DAG.getAtomic(ISD::ATOMIC_SWAP, dl,

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,9 @@ class LLVM_LIBRARY_VISIBILITY DAGTypeLegalizer {
494494
SDValue ExpandIntOp_SETCC(SDNode *N);
495495
SDValue ExpandIntOp_SETCCCARRY(SDNode *N);
496496
SDValue ExpandIntOp_Shift(SDNode *N);
497-
SDValue ExpandIntOp_SINT_TO_FP(SDNode *N);
498497
SDValue ExpandIntOp_STORE(StoreSDNode *N, unsigned OpNo);
499498
SDValue ExpandIntOp_TRUNCATE(SDNode *N);
500-
SDValue ExpandIntOp_UINT_TO_FP(SDNode *N);
499+
SDValue ExpandIntOp_XINT_TO_FP(SDNode *N);
501500
SDValue ExpandIntOp_RETURNADDR(SDNode *N);
502501
SDValue ExpandIntOp_ATOMIC_STORE(SDNode *N);
503502
SDValue ExpandIntOp_SPLAT_VECTOR(SDNode *N);

0 commit comments

Comments
 (0)