Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit ac90f79

Browse files
committed
[TargetLowering] SimplifyDemandedBits trunc(srl(x, C1)) - early out for out of range C1. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356810 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 925f591 commit ac90f79

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lib/CodeGen/SelectionDAG/TargetLowering.cpp

+19-19
Original file line numberDiff line numberDiff line change
@@ -1257,29 +1257,29 @@ bool TargetLowering::SimplifyDemandedBits(
12571257
// Do not turn (vt1 truncate (vt2 srl)) into (vt1 srl) if vt1 is
12581258
// undesirable.
12591259
break;
1260-
ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(Src.getOperand(1));
1261-
if (!ShAmt)
1260+
1261+
auto *ShAmt = dyn_cast<ConstantSDNode>(Src.getOperand(1));
1262+
if (!ShAmt || ShAmt->getAPIntValue().uge(BitWidth))
12621263
break;
1264+
12631265
SDValue Shift = Src.getOperand(1);
1264-
if (TLO.LegalTypes()) {
1265-
uint64_t ShVal = ShAmt->getZExtValue();
1266+
uint64_t ShVal = ShAmt->getZExtValue();
1267+
1268+
if (TLO.LegalTypes())
12661269
Shift = TLO.DAG.getConstant(ShVal, dl, getShiftAmountTy(VT, DL));
1267-
}
12681270

1269-
if (ShAmt->getZExtValue() < BitWidth) {
1270-
APInt HighBits = APInt::getHighBitsSet(OperandBitWidth,
1271-
OperandBitWidth - BitWidth);
1272-
HighBits.lshrInPlace(ShAmt->getZExtValue());
1273-
HighBits = HighBits.trunc(BitWidth);
1274-
1275-
if (!(HighBits & DemandedBits)) {
1276-
// None of the shifted in bits are needed. Add a truncate of the
1277-
// shift input, then shift it.
1278-
SDValue NewTrunc =
1279-
TLO.DAG.getNode(ISD::TRUNCATE, dl, VT, Src.getOperand(0));
1280-
return TLO.CombineTo(
1281-
Op, TLO.DAG.getNode(ISD::SRL, dl, VT, NewTrunc, Shift));
1282-
}
1271+
APInt HighBits =
1272+
APInt::getHighBitsSet(OperandBitWidth, OperandBitWidth - BitWidth);
1273+
HighBits.lshrInPlace(ShVal);
1274+
HighBits = HighBits.trunc(BitWidth);
1275+
1276+
if (!(HighBits & DemandedBits)) {
1277+
// None of the shifted in bits are needed. Add a truncate of the
1278+
// shift input, then shift it.
1279+
SDValue NewTrunc =
1280+
TLO.DAG.getNode(ISD::TRUNCATE, dl, VT, Src.getOperand(0));
1281+
return TLO.CombineTo(
1282+
Op, TLO.DAG.getNode(ISD::SRL, dl, VT, NewTrunc, Shift));
12831283
}
12841284
break;
12851285
}

0 commit comments

Comments
 (0)