Skip to content

Commit fdbe823

Browse files
committed
address comments
1 parent 69be811 commit fdbe823

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26367,35 +26367,38 @@ performScalarToVectorCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI,
2636726367
return NVCAST;
2636826368
}
2636926369

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.
2637026376
static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG) {
26371-
SDValue Op0 = N->getOperand(0);
26372-
SDValue Op1 = N->getOperand(1);
2637326377
EVT VT = N->getValueType(0);
2637426378
if (VT != MVT::i32 && VT != MVT::i64)
2637526379
return SDValue();
2637626380

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);
2638126382
if (!Op0.hasOneUse() || Op0.getOpcode() != ISD::AND)
2638226383
return SDValue();
2638326384

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))
2638726388
return SDValue();
2638826389

2638926390
// 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+
}
2639526397

2639626398
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);
2639926402
return DAG.getNode(ISD::AND, DL, VT, NewShift, NewRHS);
2640026403
}
2640126404

0 commit comments

Comments
 (0)