@@ -6446,12 +6446,6 @@ SDValue DAGCombiner::unfoldExtremeBitClearingToShifts(SDNode *N) {
6446
6446
static SDValue combineShiftAnd1ToBitTest(SDNode *And, SelectionDAG &DAG) {
6447
6447
assert(And->getOpcode() == ISD::AND && "Expected an 'and' op");
6448
6448
6449
- // This is probably not worthwhile without a supported type.
6450
- EVT VT = And->getValueType(0);
6451
- const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6452
- if (!TLI.isTypeLegal(VT))
6453
- return SDValue();
6454
-
6455
6449
// Look through an optional extension.
6456
6450
SDValue And0 = And->getOperand(0), And1 = And->getOperand(1);
6457
6451
if (And0.getOpcode() == ISD::ANY_EXTEND && And0.hasOneUse())
@@ -6479,13 +6473,17 @@ static SDValue combineShiftAnd1ToBitTest(SDNode *And, SelectionDAG &DAG) {
6479
6473
if (Src.getOpcode() != ISD::SRL || !Src.hasOneUse())
6480
6474
return SDValue();
6481
6475
6476
+ // This is probably not worthwhile without a supported type.
6477
+ EVT SrcVT = Src.getValueType();
6478
+ const TargetLowering &TLI = DAG.getTargetLoweringInfo();
6479
+ if (!TLI.isTypeLegal(SrcVT))
6480
+ return SDValue();
6481
+
6482
6482
// We might have looked through casts that make this transform invalid.
6483
- // TODO: If the source type is wider than the result type, do the mask and
6484
- // compare in the source type.
6485
- unsigned VTBitWidth = VT.getScalarSizeInBits();
6483
+ unsigned BitWidth = SrcVT.getScalarSizeInBits();
6486
6484
SDValue ShiftAmt = Src.getOperand(1);
6487
6485
auto *ShiftAmtC = dyn_cast<ConstantSDNode>(ShiftAmt);
6488
- if (!ShiftAmtC || !ShiftAmtC->getAPIntValue().ult(VTBitWidth ))
6486
+ if (!ShiftAmtC || !ShiftAmtC->getAPIntValue().ult(BitWidth ))
6489
6487
return SDValue();
6490
6488
6491
6489
// Set source to shift source.
@@ -6506,14 +6504,15 @@ static SDValue combineShiftAnd1ToBitTest(SDNode *And, SelectionDAG &DAG) {
6506
6504
// and (not (srl X, C)), 1 --> (and X, 1<<C) == 0
6507
6505
// and (srl (not X), C)), 1 --> (and X, 1<<C) == 0
6508
6506
SDLoc DL(And);
6509
- SDValue X = DAG.getZExtOrTrunc(Src, DL, VT);
6510
- EVT CCVT = TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
6507
+ SDValue X = DAG.getZExtOrTrunc(Src, DL, SrcVT);
6508
+ EVT CCVT =
6509
+ TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), SrcVT);
6511
6510
SDValue Mask = DAG.getConstant(
6512
- APInt::getOneBitSet(VTBitWidth , ShiftAmtC->getZExtValue()), DL, VT );
6513
- SDValue NewAnd = DAG.getNode(ISD::AND, DL, VT , X, Mask);
6514
- SDValue Zero = DAG.getConstant(0, DL, VT );
6511
+ APInt::getOneBitSet(BitWidth , ShiftAmtC->getZExtValue()), DL, SrcVT );
6512
+ SDValue NewAnd = DAG.getNode(ISD::AND, DL, SrcVT , X, Mask);
6513
+ SDValue Zero = DAG.getConstant(0, DL, SrcVT );
6515
6514
SDValue Setcc = DAG.getSetCC(DL, CCVT, NewAnd, Zero, ISD::SETEQ);
6516
- return DAG.getZExtOrTrunc(Setcc, DL, VT );
6515
+ return DAG.getZExtOrTrunc(Setcc, DL, And->getValueType(0) );
6517
6516
}
6518
6517
6519
6518
/// For targets that support usubsat, match a bit-hack form of that operation
0 commit comments