Skip to content

Commit 3c2a73a

Browse files
committed
[X86] FP<->INT helpers - share the same SDLoc argument instead of recreating it over and over again.
1 parent 92bbf61 commit 3c2a73a

File tree

1 file changed

+44
-47
lines changed

1 file changed

+44
-47
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18832,7 +18832,8 @@ static SDValue LowerShiftParts(SDValue Op, SelectionDAG &DAG) {
1883218832

1883318833
// Try to use a packed vector operation to handle i64 on 32-bit targets when
1883418834
// AVX512DQ is enabled.
18835-
static SDValue LowerI64IntToFP_AVX512DQ(SDValue Op, SelectionDAG &DAG,
18835+
static SDValue LowerI64IntToFP_AVX512DQ(SDValue Op, const SDLoc &dl,
18836+
SelectionDAG &DAG,
1883618837
const X86Subtarget &Subtarget) {
1883718838
assert((Op.getOpcode() == ISD::SINT_TO_FP ||
1883818839
Op.getOpcode() == ISD::STRICT_SINT_TO_FP ||
@@ -18856,7 +18857,6 @@ static SDValue LowerI64IntToFP_AVX512DQ(SDValue Op, SelectionDAG &DAG,
1885618857
MVT VecInVT = MVT::getVectorVT(MVT::i64, NumElts);
1885718858
MVT VecVT = MVT::getVectorVT(VT, NumElts);
1885818859

18859-
SDLoc dl(Op);
1886018860
SDValue InVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VecInVT, Src);
1886118861
if (IsStrict) {
1886218862
SDValue CvtVec = DAG.getNode(Op.getOpcode(), dl, {VecVT, MVT::Other},
@@ -18874,7 +18874,7 @@ static SDValue LowerI64IntToFP_AVX512DQ(SDValue Op, SelectionDAG &DAG,
1887418874
}
1887518875

1887618876
// Try to use a packed vector operation to handle i64 on 32-bit targets.
18877-
static SDValue LowerI64IntToFP16(SDValue Op, SelectionDAG &DAG,
18877+
static SDValue LowerI64IntToFP16(SDValue Op, const SDLoc &dl, SelectionDAG &DAG,
1887818878
const X86Subtarget &Subtarget) {
1887918879
assert((Op.getOpcode() == ISD::SINT_TO_FP ||
1888018880
Op.getOpcode() == ISD::STRICT_SINT_TO_FP ||
@@ -18893,7 +18893,6 @@ static SDValue LowerI64IntToFP16(SDValue Op, SelectionDAG &DAG,
1889318893

1889418894
assert(Subtarget.hasFP16() && "Expected FP16");
1889518895

18896-
SDLoc dl(Op);
1889718896
SDValue InVec = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2i64, Src);
1889818897
if (IsStrict) {
1889918898
SDValue CvtVec = DAG.getNode(Op.getOpcode(), dl, {MVT::v2f16, MVT::Other},
@@ -18935,7 +18934,8 @@ static bool useVectorCast(unsigned Opcode, MVT FromVT, MVT ToVT,
1893518934
/// Given a scalar cast operation that is extracted from a vector, try to
1893618935
/// vectorize the cast op followed by extraction. This will avoid an expensive
1893718936
/// round-trip between XMM and GPR.
18938-
static SDValue vectorizeExtractedCast(SDValue Cast, SelectionDAG &DAG,
18937+
static SDValue vectorizeExtractedCast(SDValue Cast, const SDLoc &DL,
18938+
SelectionDAG &DAG,
1893918939
const X86Subtarget &Subtarget) {
1894018940
// TODO: This could be enhanced to handle smaller integer types by peeking
1894118941
// through an extend.
@@ -18956,7 +18956,6 @@ static SDValue vectorizeExtractedCast(SDValue Cast, SelectionDAG &DAG,
1895618956

1895718957
// If we are extracting from a non-zero element, first shuffle the source
1895818958
// vector to allow extracting from element zero.
18959-
SDLoc DL(Cast);
1896018959
if (!isNullConstant(Extract.getOperand(1))) {
1896118960
SmallVector<int, 16> Mask(FromVT.getVectorNumElements(), -1);
1896218961
Mask[0] = Extract.getConstantOperandVal(1);
@@ -18977,7 +18976,8 @@ static SDValue vectorizeExtractedCast(SDValue Cast, SelectionDAG &DAG,
1897718976
/// Given a scalar cast to FP with a cast to integer operand (almost an ftrunc),
1897818977
/// try to vectorize the cast ops. This will avoid an expensive round-trip
1897918978
/// between XMM and GPR.
18980-
static SDValue lowerFPToIntToFP(SDValue CastToFP, SelectionDAG &DAG,
18979+
static SDValue lowerFPToIntToFP(SDValue CastToFP, const SDLoc &DL,
18980+
SelectionDAG &DAG,
1898118981
const X86Subtarget &Subtarget) {
1898218982
// TODO: Allow FP_TO_UINT.
1898318983
SDValue CastToInt = CastToFP.getOperand(0);
@@ -19016,17 +19016,16 @@ static SDValue lowerFPToIntToFP(SDValue CastToFP, SelectionDAG &DAG,
1901619016
// that could nullify any performance advantage that we hoped to gain from
1901719017
// this vector op hack. We do not expect any adverse effects (like denorm
1901819018
// penalties) with cast ops.
19019-
SDLoc DL(CastToFP);
1902019019
SDValue ZeroIdx = DAG.getIntPtrConstant(0, DL);
1902119020
SDValue VecX = DAG.getNode(ISD::SCALAR_TO_VECTOR, DL, VecSrcVT, X);
1902219021
SDValue VCastToInt = DAG.getNode(ToIntOpcode, DL, VecIntVT, VecX);
1902319022
SDValue VCastToFP = DAG.getNode(ToFPOpcode, DL, VecVT, VCastToInt);
1902419023
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, VT, VCastToFP, ZeroIdx);
1902519024
}
1902619025

19027-
static SDValue lowerINT_TO_FP_vXi64(SDValue Op, SelectionDAG &DAG,
19026+
static SDValue lowerINT_TO_FP_vXi64(SDValue Op, const SDLoc &DL,
19027+
SelectionDAG &DAG,
1902819028
const X86Subtarget &Subtarget) {
19029-
SDLoc DL(Op);
1903019029
bool IsStrict = Op->isStrictFPOpcode();
1903119030
MVT VT = Op->getSimpleValueType(0);
1903219031
SDValue Src = Op->getOperand(IsStrict ? 1 : 0);
@@ -19113,13 +19112,13 @@ static SDValue lowerINT_TO_FP_vXi64(SDValue Op, SelectionDAG &DAG,
1911319112
return Cvt;
1911419113
}
1911519114

19116-
static SDValue promoteXINT_TO_FP(SDValue Op, SelectionDAG &DAG) {
19115+
static SDValue promoteXINT_TO_FP(SDValue Op, const SDLoc &dl,
19116+
SelectionDAG &DAG) {
1911719117
bool IsStrict = Op->isStrictFPOpcode();
1911819118
SDValue Src = Op.getOperand(IsStrict ? 1 : 0);
1911919119
SDValue Chain = IsStrict ? Op->getOperand(0) : DAG.getEntryNode();
1912019120
MVT VT = Op.getSimpleValueType();
1912119121
MVT NVT = VT.isVector() ? VT.changeVectorElementType(MVT::f32) : MVT::f32;
19122-
SDLoc dl(Op);
1912319122

1912419123
SDValue Rnd = DAG.getIntPtrConstant(0, dl);
1912519124
if (IsStrict)
@@ -19163,17 +19162,17 @@ SDValue X86TargetLowering::LowerSINT_TO_FP(SDValue Op,
1916319162
SDLoc dl(Op);
1916419163

1916519164
if (isSoftF16(VT, Subtarget))
19166-
return promoteXINT_TO_FP(Op, DAG);
19165+
return promoteXINT_TO_FP(Op, dl, DAG);
1916719166
else if (isLegalConversion(SrcVT, true, Subtarget))
1916819167
return Op;
1916919168

1917019169
if (Subtarget.isTargetWin64() && SrcVT == MVT::i128)
1917119170
return LowerWin64_INT128_TO_FP(Op, DAG);
1917219171

19173-
if (SDValue Extract = vectorizeExtractedCast(Op, DAG, Subtarget))
19172+
if (SDValue Extract = vectorizeExtractedCast(Op, dl, DAG, Subtarget))
1917419173
return Extract;
1917519174

19176-
if (SDValue R = lowerFPToIntToFP(Op, DAG, Subtarget))
19175+
if (SDValue R = lowerFPToIntToFP(Op, dl, DAG, Subtarget))
1917719176
return R;
1917819177

1917919178
if (SrcVT.isVector()) {
@@ -19190,7 +19189,7 @@ SDValue X86TargetLowering::LowerSINT_TO_FP(SDValue Op,
1919019189
DAG.getUNDEF(SrcVT)));
1919119190
}
1919219191
if (SrcVT == MVT::v2i64 || SrcVT == MVT::v4i64)
19193-
return lowerINT_TO_FP_vXi64(Op, DAG, Subtarget);
19192+
return lowerINT_TO_FP_vXi64(Op, dl, DAG, Subtarget);
1919419193

1919519194
return SDValue();
1919619195
}
@@ -19207,9 +19206,9 @@ SDValue X86TargetLowering::LowerSINT_TO_FP(SDValue Op,
1920719206
if (SrcVT == MVT::i64 && UseSSEReg && Subtarget.is64Bit())
1920819207
return Op;
1920919208

19210-
if (SDValue V = LowerI64IntToFP_AVX512DQ(Op, DAG, Subtarget))
19209+
if (SDValue V = LowerI64IntToFP_AVX512DQ(Op, dl, DAG, Subtarget))
1921119210
return V;
19212-
if (SDValue V = LowerI64IntToFP16(Op, DAG, Subtarget))
19211+
if (SDValue V = LowerI64IntToFP16(Op, dl, DAG, Subtarget))
1921319212
return V;
1921419213

1921519214
// SSE doesn't have an i16 conversion so we need to promote.
@@ -19302,7 +19301,8 @@ static bool shouldUseHorizontalOp(bool IsSingleSource, SelectionDAG &DAG,
1930219301
}
1930319302

1930419303
/// 64-bit unsigned integer to double expansion.
19305-
static SDValue LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG,
19304+
static SDValue LowerUINT_TO_FP_i64(SDValue Op, const SDLoc &dl,
19305+
SelectionDAG &DAG,
1930619306
const X86Subtarget &Subtarget) {
1930719307
// We can't use this algorithm for strict fp. It produces -0.0 instead of +0.0
1930819308
// when converting 0 when rounding toward negative infinity. Caller will
@@ -19321,7 +19321,6 @@ static SDValue LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG,
1932119321
#endif
1932219322
*/
1932319323

19324-
SDLoc dl(Op);
1932519324
LLVMContext *Context = DAG.getContext();
1932619325

1932719326
// Build some magic constants.
@@ -19370,10 +19369,10 @@ static SDValue LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG,
1937019369
}
1937119370

1937219371
/// 32-bit unsigned integer to float expansion.
19373-
static SDValue LowerUINT_TO_FP_i32(SDValue Op, SelectionDAG &DAG,
19372+
static SDValue LowerUINT_TO_FP_i32(SDValue Op, const SDLoc &dl,
19373+
SelectionDAG &DAG,
1937419374
const X86Subtarget &Subtarget) {
1937519375
unsigned OpNo = Op.getNode()->isStrictFPOpcode() ? 1 : 0;
19376-
SDLoc dl(Op);
1937719376
// FP constant to bias correct the final result.
1937819377
SDValue Bias = DAG.getConstantFP(
1937919378
llvm::bit_cast<double>(0x4330000000000000ULL), dl, MVT::f64);
@@ -19420,9 +19419,9 @@ static SDValue LowerUINT_TO_FP_i32(SDValue Op, SelectionDAG &DAG,
1942019419
return DAG.getFPExtendOrRound(Sub, dl, Op.getSimpleValueType());
1942119420
}
1942219421

19423-
static SDValue lowerUINT_TO_FP_v2i32(SDValue Op, SelectionDAG &DAG,
19424-
const X86Subtarget &Subtarget,
19425-
const SDLoc &DL) {
19422+
static SDValue lowerUINT_TO_FP_v2i32(SDValue Op, const SDLoc &DL,
19423+
SelectionDAG &DAG,
19424+
const X86Subtarget &Subtarget) {
1942619425
if (Op.getSimpleValueType() != MVT::v2f64)
1942719426
return SDValue();
1942819427

@@ -19473,9 +19472,9 @@ static SDValue lowerUINT_TO_FP_v2i32(SDValue Op, SelectionDAG &DAG,
1947319472
return DAG.getNode(ISD::FSUB, DL, MVT::v2f64, Or, VBias);
1947419473
}
1947519474

19476-
static SDValue lowerUINT_TO_FP_vXi32(SDValue Op, SelectionDAG &DAG,
19475+
static SDValue lowerUINT_TO_FP_vXi32(SDValue Op, const SDLoc &DL,
19476+
SelectionDAG &DAG,
1947719477
const X86Subtarget &Subtarget) {
19478-
SDLoc DL(Op);
1947919478
bool IsStrict = Op->isStrictFPOpcode();
1948019479
SDValue V = Op->getOperand(IsStrict ? 1 : 0);
1948119480
MVT VecIntVT = V.getSimpleValueType();
@@ -19631,24 +19630,23 @@ static SDValue lowerUINT_TO_FP_vXi32(SDValue Op, SelectionDAG &DAG,
1963119630
return DAG.getNode(ISD::FADD, DL, VecFloatVT, LowBitcast, FHigh);
1963219631
}
1963319632

19634-
static SDValue lowerUINT_TO_FP_vec(SDValue Op, SelectionDAG &DAG,
19633+
static SDValue lowerUINT_TO_FP_vec(SDValue Op, const SDLoc &dl, SelectionDAG &DAG,
1963519634
const X86Subtarget &Subtarget) {
1963619635
unsigned OpNo = Op.getNode()->isStrictFPOpcode() ? 1 : 0;
1963719636
SDValue N0 = Op.getOperand(OpNo);
1963819637
MVT SrcVT = N0.getSimpleValueType();
19639-
SDLoc dl(Op);
1964019638

1964119639
switch (SrcVT.SimpleTy) {
1964219640
default:
1964319641
llvm_unreachable("Custom UINT_TO_FP is not supported!");
1964419642
case MVT::v2i32:
19645-
return lowerUINT_TO_FP_v2i32(Op, DAG, Subtarget, dl);
19643+
return lowerUINT_TO_FP_v2i32(Op, dl, DAG, Subtarget);
1964619644
case MVT::v4i32:
1964719645
case MVT::v8i32:
19648-
return lowerUINT_TO_FP_vXi32(Op, DAG, Subtarget);
19646+
return lowerUINT_TO_FP_vXi32(Op, dl, DAG, Subtarget);
1964919647
case MVT::v2i64:
1965019648
case MVT::v4i64:
19651-
return lowerINT_TO_FP_vXi64(Op, DAG, Subtarget);
19649+
return lowerINT_TO_FP_vXi64(Op, dl, DAG, Subtarget);
1965219650
}
1965319651
}
1965419652

@@ -19668,17 +19666,17 @@ SDValue X86TargetLowering::LowerUINT_TO_FP(SDValue Op,
1966819666
return SDValue();
1966919667

1967019668
if (isSoftF16(DstVT, Subtarget))
19671-
return promoteXINT_TO_FP(Op, DAG);
19669+
return promoteXINT_TO_FP(Op, dl, DAG);
1967219670
else if (isLegalConversion(SrcVT, false, Subtarget))
1967319671
return Op;
1967419672

1967519673
if (DstVT.isVector())
19676-
return lowerUINT_TO_FP_vec(Op, DAG, Subtarget);
19674+
return lowerUINT_TO_FP_vec(Op, dl, DAG, Subtarget);
1967719675

1967819676
if (Subtarget.isTargetWin64() && SrcVT == MVT::i128)
1967919677
return LowerWin64_INT128_TO_FP(Op, DAG);
1968019678

19681-
if (SDValue Extract = vectorizeExtractedCast(Op, DAG, Subtarget))
19679+
if (SDValue Extract = vectorizeExtractedCast(Op, dl, DAG, Subtarget))
1968219680
return Extract;
1968319681

1968419682
if (Subtarget.hasAVX512() && isScalarFPTypeInSSEReg(DstVT) &&
@@ -19697,21 +19695,21 @@ SDValue X86TargetLowering::LowerUINT_TO_FP(SDValue Op,
1969719695
return DAG.getNode(ISD::SINT_TO_FP, dl, DstVT, Src);
1969819696
}
1969919697

19700-
if (SDValue V = LowerI64IntToFP_AVX512DQ(Op, DAG, Subtarget))
19698+
if (SDValue V = LowerI64IntToFP_AVX512DQ(Op, dl, DAG, Subtarget))
1970119699
return V;
19702-
if (SDValue V = LowerI64IntToFP16(Op, DAG, Subtarget))
19700+
if (SDValue V = LowerI64IntToFP16(Op, dl, DAG, Subtarget))
1970319701
return V;
1970419702

1970519703
// The transform for i64->f64 isn't correct for 0 when rounding to negative
1970619704
// infinity. It produces -0.0, so disable under strictfp.
1970719705
if (SrcVT == MVT::i64 && DstVT == MVT::f64 && Subtarget.hasSSE2() &&
1970819706
!IsStrict)
19709-
return LowerUINT_TO_FP_i64(Op, DAG, Subtarget);
19707+
return LowerUINT_TO_FP_i64(Op, dl, DAG, Subtarget);
1971019708
// The transform for i32->f64/f32 isn't correct for 0 when rounding to
1971119709
// negative infinity. So disable under strictfp. Using FILD instead.
1971219710
if (SrcVT == MVT::i32 && Subtarget.hasSSE2() && DstVT != MVT::f80 &&
1971319711
!IsStrict)
19714-
return LowerUINT_TO_FP_i32(Op, DAG, Subtarget);
19712+
return LowerUINT_TO_FP_i32(Op, dl, DAG, Subtarget);
1971519713
if (Subtarget.is64Bit() && SrcVT == MVT::i64 &&
1971619714
(DstVT == MVT::f32 || DstVT == MVT::f64))
1971719715
return SDValue();
@@ -19721,7 +19719,7 @@ SDValue X86TargetLowering::LowerUINT_TO_FP(SDValue Op,
1972119719
int SSFI = cast<FrameIndexSDNode>(StackSlot)->getIndex();
1972219720
Align SlotAlign(8);
1972319721
MachinePointerInfo MPI =
19724-
MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), SSFI);
19722+
MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), SSFI);
1972519723
if (SrcVT == MVT::i32) {
1972619724
SDValue OffsetSlot =
1972719725
DAG.getMemBasePlusOffset(StackSlot, TypeSize::getFixed(4), dl);
@@ -19750,22 +19748,21 @@ SDValue X86TargetLowering::LowerUINT_TO_FP(SDValue Op,
1975019748
// was negative. We must be careful to do the computation in x87 extended
1975119749
// precision, not in SSE.
1975219750
SDVTList Tys = DAG.getVTList(MVT::f80, MVT::Other);
19753-
SDValue Ops[] = { Store, StackSlot };
19751+
SDValue Ops[] = {Store, StackSlot};
1975419752
SDValue Fild =
1975519753
DAG.getMemIntrinsicNode(X86ISD::FILD, dl, Tys, Ops, MVT::i64, MPI,
1975619754
SlotAlign, MachineMemOperand::MOLoad);
1975719755
Chain = Fild.getValue(1);
1975819756

19759-
1976019757
// Check whether the sign bit is set.
1976119758
SDValue SignSet = DAG.getSetCC(
1976219759
dl, getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), MVT::i64),
1976319760
Op.getOperand(OpNo), DAG.getConstant(0, dl, MVT::i64), ISD::SETLT);
1976419761

1976519762
// Build a 64 bit pair (FF, 0) in the constant pool, with FF in the hi bits.
1976619763
APInt FF(64, 0x5F80000000000000ULL);
19767-
SDValue FudgePtr = DAG.getConstantPool(
19768-
ConstantInt::get(*DAG.getContext(), FF), PtrVT);
19764+
SDValue FudgePtr =
19765+
DAG.getConstantPool(ConstantInt::get(*DAG.getContext(), FF), PtrVT);
1976919766
Align CPAlignment = cast<ConstantPoolSDNode>(FudgePtr)->getAlign();
1977019767

1977119768
// Get a pointer to FF if the sign bit was set, or to 0 otherwise.
@@ -19812,9 +19809,9 @@ SDValue X86TargetLowering::LowerUINT_TO_FP(SDValue Op,
1981219809
// Otherwise it is assumed to be a conversion from one of f32, f64 or f80
1981319810
// to i16, i32 or i64, and we lower it to a legal sequence and return the
1981419811
// result.
19815-
SDValue
19816-
X86TargetLowering::FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG,
19817-
bool IsSigned, SDValue &Chain) const {
19812+
SDValue X86TargetLowering::FP_TO_INTHelper(SDValue Op, SelectionDAG &DAG,
19813+
bool IsSigned,
19814+
SDValue &Chain) const {
1981819815
bool IsStrict = Op->isStrictFPOpcode();
1981919816
SDLoc DL(Op);
1982019817

0 commit comments

Comments
 (0)