Skip to content

Commit 8268bc4

Browse files
committed
[DAG] Avoid SDLoc duplication in FP<->INT combines. NFC.
1 parent 067e8b8 commit 8268bc4

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17964,7 +17964,7 @@ SDValue DAGCombiner::visitFPOW(SDNode *N) {
1796417964
return SDValue();
1796517965
}
1796617966

17967-
static SDValue foldFPToIntToFP(SDNode *N, SelectionDAG &DAG,
17967+
static SDValue foldFPToIntToFP(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
1796817968
const TargetLowering &TLI) {
1796917969
// We only do this if the target has legal ftrunc. Otherwise, we'd likely be
1797017970
// replacing casts with a libcall. We also must be allowed to ignore -0.0
@@ -17982,11 +17982,11 @@ static SDValue foldFPToIntToFP(SDNode *N, SelectionDAG &DAG,
1798217982
SDValue N0 = N->getOperand(0);
1798317983
if (N->getOpcode() == ISD::SINT_TO_FP && N0.getOpcode() == ISD::FP_TO_SINT &&
1798417984
N0.getOperand(0).getValueType() == VT)
17985-
return DAG.getNode(ISD::FTRUNC, SDLoc(N), VT, N0.getOperand(0));
17985+
return DAG.getNode(ISD::FTRUNC, DL, VT, N0.getOperand(0));
1798617986

1798717987
if (N->getOpcode() == ISD::UINT_TO_FP && N0.getOpcode() == ISD::FP_TO_UINT &&
1798817988
N0.getOperand(0).getValueType() == VT)
17989-
return DAG.getNode(ISD::FTRUNC, SDLoc(N), VT, N0.getOperand(0));
17989+
return DAG.getNode(ISD::FTRUNC, DL, VT, N0.getOperand(0));
1799017990

1799117991
return SDValue();
1799217992
}
@@ -17995,49 +17995,45 @@ SDValue DAGCombiner::visitSINT_TO_FP(SDNode *N) {
1799517995
SDValue N0 = N->getOperand(0);
1799617996
EVT VT = N->getValueType(0);
1799717997
EVT OpVT = N0.getValueType();
17998+
SDLoc DL(N);
1799817999

1799918000
// [us]itofp(undef) = 0, because the result value is bounded.
1800018001
if (N0.isUndef())
18001-
return DAG.getConstantFP(0.0, SDLoc(N), VT);
18002+
return DAG.getConstantFP(0.0, DL, VT);
1800218003

1800318004
// fold (sint_to_fp c1) -> c1fp
1800418005
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
1800518006
// ...but only if the target supports immediate floating-point values
18006-
(!LegalOperations ||
18007-
TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18008-
return DAG.getNode(ISD::SINT_TO_FP, SDLoc(N), VT, N0);
18007+
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18008+
return DAG.getNode(ISD::SINT_TO_FP, DL, VT, N0);
1800918009

1801018010
// If the input is a legal type, and SINT_TO_FP is not legal on this target,
1801118011
// but UINT_TO_FP is legal on this target, try to convert.
1801218012
if (!hasOperation(ISD::SINT_TO_FP, OpVT) &&
1801318013
hasOperation(ISD::UINT_TO_FP, OpVT)) {
1801418014
// If the sign bit is known to be zero, we can change this to UINT_TO_FP.
1801518015
if (DAG.SignBitIsZero(N0))
18016-
return DAG.getNode(ISD::UINT_TO_FP, SDLoc(N), VT, N0);
18016+
return DAG.getNode(ISD::UINT_TO_FP, DL, VT, N0);
1801718017
}
1801818018

1801918019
// The next optimizations are desirable only if SELECT_CC can be lowered.
1802018020
// fold (sint_to_fp (setcc x, y, cc)) -> (select (setcc x, y, cc), -1.0, 0.0)
1802118021
if (N0.getOpcode() == ISD::SETCC && N0.getValueType() == MVT::i1 &&
1802218022
!VT.isVector() &&
18023-
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT))) {
18024-
SDLoc DL(N);
18023+
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
1802518024
return DAG.getSelect(DL, VT, N0, DAG.getConstantFP(-1.0, DL, VT),
1802618025
DAG.getConstantFP(0.0, DL, VT));
18027-
}
1802818026

1802918027
// fold (sint_to_fp (zext (setcc x, y, cc))) ->
1803018028
// (select (setcc x, y, cc), 1.0, 0.0)
1803118029
if (N0.getOpcode() == ISD::ZERO_EXTEND &&
1803218030
N0.getOperand(0).getOpcode() == ISD::SETCC && !VT.isVector() &&
18033-
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT))) {
18034-
SDLoc DL(N);
18031+
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
1803518032
return DAG.getSelect(DL, VT, N0.getOperand(0),
1803618033
DAG.getConstantFP(1.0, DL, VT),
1803718034
DAG.getConstantFP(0.0, DL, VT));
18038-
}
1803918035

18040-
if (SDValue FTrunc = foldFPToIntToFP(N, DAG, TLI))
18036+
if (SDValue FTrunc = foldFPToIntToFP(N, DL, DAG, TLI))
1804118037
return FTrunc;
1804218038

1804318039
return SDValue();
@@ -18047,43 +18043,41 @@ SDValue DAGCombiner::visitUINT_TO_FP(SDNode *N) {
1804718043
SDValue N0 = N->getOperand(0);
1804818044
EVT VT = N->getValueType(0);
1804918045
EVT OpVT = N0.getValueType();
18046+
SDLoc DL(N);
1805018047

1805118048
// [us]itofp(undef) = 0, because the result value is bounded.
1805218049
if (N0.isUndef())
18053-
return DAG.getConstantFP(0.0, SDLoc(N), VT);
18050+
return DAG.getConstantFP(0.0, DL, VT);
1805418051

1805518052
// fold (uint_to_fp c1) -> c1fp
1805618053
if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
1805718054
// ...but only if the target supports immediate floating-point values
18058-
(!LegalOperations ||
18059-
TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18060-
return DAG.getNode(ISD::UINT_TO_FP, SDLoc(N), VT, N0);
18055+
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
18056+
return DAG.getNode(ISD::UINT_TO_FP, DL, VT, N0);
1806118057

1806218058
// If the input is a legal type, and UINT_TO_FP is not legal on this target,
1806318059
// but SINT_TO_FP is legal on this target, try to convert.
1806418060
if (!hasOperation(ISD::UINT_TO_FP, OpVT) &&
1806518061
hasOperation(ISD::SINT_TO_FP, OpVT)) {
1806618062
// If the sign bit is known to be zero, we can change this to SINT_TO_FP.
1806718063
if (DAG.SignBitIsZero(N0))
18068-
return DAG.getNode(ISD::SINT_TO_FP, SDLoc(N), VT, N0);
18064+
return DAG.getNode(ISD::SINT_TO_FP, DL, VT, N0);
1806918065
}
1807018066

1807118067
// fold (uint_to_fp (setcc x, y, cc)) -> (select (setcc x, y, cc), 1.0, 0.0)
1807218068
if (N0.getOpcode() == ISD::SETCC && !VT.isVector() &&
18073-
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT))) {
18074-
SDLoc DL(N);
18069+
(!LegalOperations || TLI.isOperationLegalOrCustom(ISD::ConstantFP, VT)))
1807518070
return DAG.getSelect(DL, VT, N0, DAG.getConstantFP(1.0, DL, VT),
1807618071
DAG.getConstantFP(0.0, DL, VT));
18077-
}
1807818072

18079-
if (SDValue FTrunc = foldFPToIntToFP(N, DAG, TLI))
18073+
if (SDValue FTrunc = foldFPToIntToFP(N, DL, DAG, TLI))
1808018074
return FTrunc;
1808118075

1808218076
return SDValue();
1808318077
}
1808418078

1808518079
// Fold (fp_to_{s/u}int ({s/u}int_to_fpx)) -> zext x, sext x, trunc x, or x
18086-
static SDValue FoldIntToFPToInt(SDNode *N, SelectionDAG &DAG) {
18080+
static SDValue FoldIntToFPToInt(SDNode *N, const SDLoc &DL, SelectionDAG &DAG) {
1808718081
SDValue N0 = N->getOperand(0);
1808818082
EVT VT = N->getValueType(0);
1808918083

@@ -18113,12 +18107,12 @@ static SDValue FoldIntToFPToInt(SDNode *N, SelectionDAG &DAG) {
1811318107
// represented exactly in the float range.
1811418108
if (APFloat::semanticsPrecision(Sem) >= ActualSize) {
1811518109
if (VT.getScalarSizeInBits() > SrcVT.getScalarSizeInBits()) {
18116-
unsigned ExtOp = IsInputSigned && IsOutputSigned ? ISD::SIGN_EXTEND
18117-
: ISD::ZERO_EXTEND;
18118-
return DAG.getNode(ExtOp, SDLoc(N), VT, Src);
18110+
unsigned ExtOp =
18111+
IsInputSigned && IsOutputSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
18112+
return DAG.getNode(ExtOp, DL, VT, Src);
1811918113
}
1812018114
if (VT.getScalarSizeInBits() < SrcVT.getScalarSizeInBits())
18121-
return DAG.getNode(ISD::TRUNCATE, SDLoc(N), VT, Src);
18115+
return DAG.getNode(ISD::TRUNCATE, DL, VT, Src);
1812218116
return DAG.getBitcast(VT, Src);
1812318117
}
1812418118
return SDValue();
@@ -18127,31 +18121,33 @@ static SDValue FoldIntToFPToInt(SDNode *N, SelectionDAG &DAG) {
1812718121
SDValue DAGCombiner::visitFP_TO_SINT(SDNode *N) {
1812818122
SDValue N0 = N->getOperand(0);
1812918123
EVT VT = N->getValueType(0);
18124+
SDLoc DL(N);
1813018125

1813118126
// fold (fp_to_sint undef) -> undef
1813218127
if (N0.isUndef())
1813318128
return DAG.getUNDEF(VT);
1813418129

1813518130
// fold (fp_to_sint c1fp) -> c1
1813618131
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18137-
return DAG.getNode(ISD::FP_TO_SINT, SDLoc(N), VT, N0);
18132+
return DAG.getNode(ISD::FP_TO_SINT, DL, VT, N0);
1813818133

18139-
return FoldIntToFPToInt(N, DAG);
18134+
return FoldIntToFPToInt(N, DL, DAG);
1814018135
}
1814118136

1814218137
SDValue DAGCombiner::visitFP_TO_UINT(SDNode *N) {
1814318138
SDValue N0 = N->getOperand(0);
1814418139
EVT VT = N->getValueType(0);
18140+
SDLoc DL(N);
1814518141

1814618142
// fold (fp_to_uint undef) -> undef
1814718143
if (N0.isUndef())
1814818144
return DAG.getUNDEF(VT);
1814918145

1815018146
// fold (fp_to_uint c1fp) -> c1
1815118147
if (DAG.isConstantFPBuildVectorOrConstantFP(N0))
18152-
return DAG.getNode(ISD::FP_TO_UINT, SDLoc(N), VT, N0);
18148+
return DAG.getNode(ISD::FP_TO_UINT, DL, VT, N0);
1815318149

18154-
return FoldIntToFPToInt(N, DAG);
18150+
return FoldIntToFPToInt(N, DL, DAG);
1815518151
}
1815618152

1815718153
SDValue DAGCombiner::visitXROUND(SDNode *N) {

0 commit comments

Comments
 (0)