@@ -26367,35 +26367,38 @@ performScalarToVectorCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
26367
26367
return NVCAST;
26368
26368
}
26369
26369
26370
+ /// If the operand is a bitwise AND with a constant RHS, and the shift has a
26371
+ /// constant RHS and is the only use, we can pull it out of the shift, i.e.
26372
+ ///
26373
+ /// (shl (and X, C1), C2) -> (and (shl X, C2), (shl C1, C2))
26374
+ ///
26375
+ /// We prefer this canonical form to match existing isel patterns.
26370
26376
static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG) {
26371
- SDValue Op0 = N->getOperand(0);
26372
- SDValue Op1 = N->getOperand(1);
26373
26377
EVT VT = N->getValueType(0);
26374
26378
if (VT != MVT::i32 && VT != MVT::i64)
26375
26379
return SDValue();
26376
26380
26377
- // If the operand is a bitwise AND with a constant RHS, and the shift is the
26378
- // only use, we can pull it out of the shift.
26379
- //
26380
- // (shl (and X, C1), C2) -> (and (shl X, C2), (shl C1, C2))
26381
+ SDValue Op0 = N->getOperand(0);
26381
26382
if (!Op0.hasOneUse() || Op0.getOpcode() != ISD::AND)
26382
26383
return SDValue();
26383
26384
26384
- ConstantSDNode * C1 = dyn_cast<ConstantSDNode>( Op0. getOperand(1) );
26385
- ConstantSDNode * C2 = dyn_cast<ConstantSDNode>(Op1 );
26386
- if (!C1 || !C2 )
26385
+ SDValue C1 = Op0-> getOperand(1);
26386
+ SDValue C2 = N->getOperand(1 );
26387
+ if (!isa<ConstantSDNode>(C1) || !isa<ConstantSDNode>(C2) )
26387
26388
return SDValue();
26388
26389
26389
26390
// Might be folded into shifted op, do not lower.
26390
- unsigned UseOpc = N->use_begin()->getOpcode();
26391
- if (N->hasOneUse() &&
26392
- (UseOpc == ISD::ADD || UseOpc == ISD::SUB || UseOpc == ISD::SETCC ||
26393
- UseOpc == AArch64ISD::ADDS || UseOpc == AArch64ISD::SUBS))
26394
- return SDValue();
26391
+ if (N->hasOneUse()) {
26392
+ unsigned UseOpc = N->use_begin()->getOpcode();
26393
+ if (UseOpc == ISD::ADD || UseOpc == ISD::SUB || UseOpc == ISD::SETCC ||
26394
+ UseOpc == AArch64ISD::ADDS || UseOpc == AArch64ISD::SUBS)
26395
+ return SDValue();
26396
+ }
26395
26397
26396
26398
SDLoc DL(N);
26397
- SDValue NewRHS = DAG.getNode(ISD::SHL, DL, VT, Op0.getOperand(1), Op1);
26398
- SDValue NewShift = DAG.getNode(ISD::SHL, DL, VT, Op0->getOperand(0), Op1);
26399
+ SDValue X = Op0->getOperand(0);
26400
+ SDValue NewRHS = DAG.getNode(ISD::SHL, DL, VT, C1, C2);
26401
+ SDValue NewShift = DAG.getNode(ISD::SHL, DL, VT, X, C2);
26399
26402
return DAG.getNode(ISD::AND, DL, VT, NewShift, NewRHS);
26400
26403
}
26401
26404
0 commit comments