[DAG] visitMUL - cleanup pattern matchers to use m_Shl and (commutative) m_Mul directly (#190339)

Based on feedback on #190215
This commit is contained in:
Simon Pilgrim 2026-04-03 14:21:51 +01:00 committed by GitHub
parent c963092b0c
commit 5674755cb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -4914,29 +4914,23 @@ template <class MatchContextClass> SDValue DAGCombiner::visitMUL(SDNode *N) {
}
// (mul (shl X, c1), c2) -> (mul X, c2 << c1)
if (sd_context_match(N0, Matcher, m_Opc(ISD::SHL))) {
SDValue N01 = N0.getOperand(1);
if (SDValue C3 = DAG.FoldConstantArithmetic(ISD::SHL, DL, VT, {N1, N01}))
return DAG.getNode(ISD::MUL, DL, VT, N0.getOperand(0), C3);
{
SDValue X, C1;
if (sd_context_match(N0, Matcher, m_Shl(m_Value(X), m_Value(C1))))
if (SDValue C3 = DAG.FoldConstantArithmetic(ISD::SHL, DL, VT, {N1, C1}))
return DAG.getNode(ISD::MUL, DL, VT, X, C3);
}
// Change (mul (shl X, C), Y) -> (shl (mul X, Y), C) when the shift has one
// use.
{
SDValue Sh, Y;
// Check for both (mul (shl X, C), Y) and (mul Y, (shl X, C)).
if (sd_context_match(N0, Matcher, m_OneUse(m_Opc(ISD::SHL))) &&
isConstantOrConstantVector(N0.getOperand(1))) {
Sh = N0; Y = N1;
} else if (sd_context_match(N1, Matcher, m_OneUse(m_Opc(ISD::SHL))) &&
isConstantOrConstantVector(N1.getOperand(1))) {
Sh = N1; Y = N0;
}
if (Sh.getNode()) {
SDValue Mul = Matcher.getNode(ISD::MUL, DL, VT, Sh.getOperand(0), Y);
return Matcher.getNode(ISD::SHL, DL, VT, Mul, Sh.getOperand(1));
SDValue X, C, Y;
if (sd_context_match(
N, Matcher,
m_Mul(m_OneUse(m_Shl(m_Value(X), m_Value(C))), m_Value(Y))) &&
isConstantOrConstantVector(C)) {
SDValue Mul = Matcher.getNode(ISD::MUL, DL, VT, X, Y);
return Matcher.getNode(ISD::SHL, DL, VT, Mul, C);
}
}