@@ -1886,15 +1886,15 @@ bool TargetLowering::SimplifyDemandedBits(
1886
1886
1887
1887
// Narrow shift to lower half - similar to ShrinkDemandedOp.
1888
1888
// (srl i64:x, K) -> (i64 zero_extend (srl (i32 (trunc i64:x)), K))
1889
- if ((BitWidth % 2 ) == 0 && !VT.isVector () &&
1890
- ((InDemandedMask.countLeadingZeros () >= (BitWidth / 2 )) ||
1891
- TLO.DAG .MaskedValueIsZero (
1892
- Op0, APInt::getHighBitsSet (BitWidth, BitWidth / 2 )))) {
1889
+ if ((BitWidth % 2 ) == 0 && !VT.isVector ()) {
1890
+ APInt HiBits = APInt::getHighBitsSet (BitWidth, BitWidth / 2 );
1893
1891
EVT HalfVT = EVT::getIntegerVT (*TLO.DAG .getContext (), BitWidth / 2 );
1894
1892
if (isNarrowingProfitable (VT, HalfVT) &&
1895
1893
isTypeDesirableForOp (ISD::SRL, HalfVT) &&
1896
1894
isTruncateFree (VT, HalfVT) && isZExtFree (HalfVT, VT) &&
1897
- (!TLO.LegalOperations () || isOperationLegal (ISD::SRL, VT))) {
1895
+ (!TLO.LegalOperations () || isOperationLegal (ISD::SRL, VT)) &&
1896
+ ((InDemandedMask.countLeadingZeros () >= (BitWidth / 2 )) ||
1897
+ TLO.DAG .MaskedValueIsZero (Op0, HiBits))) {
1898
1898
SDValue NewOp = TLO.DAG .getNode (ISD::TRUNCATE, dl, HalfVT, Op0);
1899
1899
SDValue NewShiftAmt = TLO.DAG .getShiftAmountConstant (
1900
1900
ShAmt, HalfVT, dl, TLO.LegalTypes ());
0 commit comments