[X86] Use getConstantOperandAPInt to detect out-of-range shifts.

llvm-svn: 356549
This commit is contained in:
Simon Pilgrim 2019-03-20 11:41:52 +00:00
parent 4bfe83679d
commit 2acca37a2d
1 changed files with 5 additions and 5 deletions

View File

@ -41161,11 +41161,12 @@ static SDValue combineCMP(SDNode *N, SelectionDAG &DAG) {
onlyZeroFlagUsed(SDValue(N, 0))) {
EVT VT = Op.getValueType();
unsigned BitWidth = VT.getSizeInBits();
unsigned ShAmt = Op.getConstantOperandVal(1);
if (ShAmt < BitWidth) { // Avoid undefined shifts.
const APInt &ShAmt = Op.getConstantOperandAPInt(1);
if (ShAmt.ult(BitWidth)) { // Avoid undefined shifts.
unsigned MaskBits = BitWidth - ShAmt.getZExtValue();
APInt Mask = Op.getOpcode() == ISD::SRL
? APInt::getHighBitsSet(BitWidth, BitWidth - ShAmt)
: APInt::getLowBitsSet(BitWidth, BitWidth - ShAmt);
? APInt::getHighBitsSet(BitWidth, MaskBits)
: APInt::getLowBitsSet(BitWidth, MaskBits);
if (Mask.isSignedIntN(32)) {
Op = DAG.getNode(ISD::AND, dl, VT, Op.getOperand(0),
DAG.getConstant(Mask, dl, VT));
@ -41175,7 +41176,6 @@ static SDValue combineCMP(SDNode *N, SelectionDAG &DAG) {
}
}
// Look for a truncate with a single use.
if (Op.getOpcode() != ISD::TRUNCATE || !Op.hasOneUse())
return SDValue();