@@ -1257,29 +1257,29 @@ bool TargetLowering::SimplifyDemandedBits(
1257
1257
// Do not turn (vt1 truncate (vt2 srl)) into (vt1 srl) if vt1 is
1258
1258
// undesirable.
1259
1259
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))
1262
1263
break ;
1264
+
1263
1265
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 ())
1266
1269
Shift = TLO.DAG .getConstant (ShVal, dl, getShiftAmountTy (VT, DL));
1267
- }
1268
1270
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));
1283
1283
}
1284
1284
break ;
1285
1285
}
0 commit comments