Skip to content

Commit 4ebd202

Browse files
authored
[LegalizeTypes][X86] Use getShiftAmountConstant in ExpandIntRes_SIGN_EXTEND. (#158388)
This ensures we don't need to fixup the shift amount later. Unfortunately, this enabled the (SRA (SHL X, ShlConst), SraConst) -> (SRA (sext_in_reg X), SraConst - ShlConst) combine in combineShiftRightArithmetic for some cases in is_fpclass-fp80.ll. So we need to also update checkSignTestSetCCCombine to look through sign_extend_inreg to prevent a regression.
1 parent 004f209 commit 4ebd202

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5088,9 +5088,8 @@ void DAGTypeLegalizer::ExpandIntRes_SIGN_EXTEND(SDNode *N,
50885088
Lo = DAG.getNode(ISD::SIGN_EXTEND, dl, NVT, N->getOperand(0));
50895089
// The high part is obtained by SRA'ing all but one of the bits of low part.
50905090
unsigned LoSize = NVT.getSizeInBits();
5091-
Hi = DAG.getNode(
5092-
ISD::SRA, dl, NVT, Lo,
5093-
DAG.getConstant(LoSize - 1, dl, TLI.getPointerTy(DAG.getDataLayout())));
5091+
Hi = DAG.getNode(ISD::SRA, dl, NVT, Lo,
5092+
DAG.getShiftAmountConstant(LoSize - 1, NVT, dl));
50945093
} else {
50955094
// For example, extension of an i48 to an i64. The operand type necessarily
50965095
// promotes to the result type, so will end up being expanded too.
@@ -5123,8 +5122,8 @@ ExpandIntRes_SIGN_EXTEND_INREG(SDNode *N, SDValue &Lo, SDValue &Hi) {
51235122
// The high part gets the sign extension from the lo-part. This handles
51245123
// things like sextinreg V:i64 from i8.
51255124
Hi = DAG.getNode(ISD::SRA, dl, Hi.getValueType(), Lo,
5126-
DAG.getConstant(Hi.getValueSizeInBits() - 1, dl,
5127-
TLI.getPointerTy(DAG.getDataLayout())));
5125+
DAG.getShiftAmountConstant(Hi.getValueSizeInBits() - 1,
5126+
Hi.getValueType(), dl));
51285127
} else {
51295128
// For example, extension of an i48 to an i64. Leave the low part alone,
51305129
// sext_inreg the high part.

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48396,13 +48396,17 @@ static SDValue checkSignTestSetCCCombine(SDValue Cmp, X86::CondCode &CC,
4839648396
MVT SrcVT = Src.getSimpleValueType();
4839748397
APInt BitMask = APInt::getSignMask(SrcVT.getScalarSizeInBits());
4839848398

48399-
// If Src came from a SHL (probably from an expanded SIGN_EXTEND_INREG), then
48400-
// peek through and adjust the TEST bit.
48399+
// If Src came from a SIGN_EXTEND_INREG or SHL (probably from an expanded
48400+
// SIGN_EXTEND_INREG), then peek through and adjust the TEST bit.
4840148401
if (Src.getOpcode() == ISD::SHL) {
4840248402
if (std::optional<unsigned> ShiftAmt = DAG.getValidShiftAmount(Src)) {
4840348403
Src = Src.getOperand(0);
4840448404
BitMask.lshrInPlace(*ShiftAmt);
4840548405
}
48406+
} else if (Src.getOpcode() == ISD::SIGN_EXTEND_INREG) {
48407+
EVT ExtVT = cast<VTSDNode>(Src.getOperand(1))->getVT();
48408+
Src = Src.getOperand(0);
48409+
BitMask.lshrInPlace(BitMask.getBitWidth() - ExtVT.getScalarSizeInBits());
4840648410
}
4840748411

4840848412
SDValue Mask = DAG.getNode(ISD::AND, DL, SrcVT, Src,

0 commit comments

Comments
 (0)