Skip to content

Commit d485317

Browse files
authored
[TargetLowering] Emit SIGN_EXTEND_INREG instead of shift pair from optimizeSetCCOfSignedTruncationCheck. (#81785)
sext_inreg is our canonical form of shift pair before op legalization so DAG combiner will probably create it anyway. If it isn't legal LegalizeDAG will expand to shifts later.
1 parent 6cfbf8c commit d485317

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,17 +4084,12 @@ SDValue TargetLowering::optimizeSetCCOfSignedTruncationCheck(
40844084
XVT, KeptBits))
40854085
return SDValue();
40864086

4087-
const unsigned MaskedBits = XVT.getSizeInBits() - KeptBits;
4088-
assert(MaskedBits > 0 && MaskedBits < XVT.getSizeInBits() && "unreachable");
4089-
4090-
// Unfold into: ((%x << C) a>> C) cond %x
4087+
// Unfold into: sext_inreg(%x) cond %x
40914088
// Where 'cond' will be either 'eq' or 'ne'.
4092-
SDValue ShiftAmt = DAG.getConstant(MaskedBits, DL, XVT);
4093-
SDValue T0 = DAG.getNode(ISD::SHL, DL, XVT, X, ShiftAmt);
4094-
SDValue T1 = DAG.getNode(ISD::SRA, DL, XVT, T0, ShiftAmt);
4095-
SDValue T2 = DAG.getSetCC(DL, SCCVT, T1, X, NewCond);
4096-
4097-
return T2;
4089+
SDValue SExtInReg = DAG.getNode(
4090+
ISD::SIGN_EXTEND_INREG, DL, XVT, X,
4091+
DAG.getValueType(EVT::getIntegerVT(*DAG.getContext(), KeptBits)));
4092+
return DAG.getSetCC(DL, SCCVT, SExtInReg, X, NewCond);
40984093
}
40994094

41004095
// (X & (C l>>/<< Y)) ==/!= 0 --> ((X <</l>> Y) & C) ==/!= 0

0 commit comments

Comments
 (0)