[llvm] 5674755 - [DAG] visitMUL - cleanup pattern matchers to use m_Shl and (commutative) m_Mul directly (#190339)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 06:21:57 PDT 2026
Author: Simon Pilgrim
Date: 2026-04-03T13:21:51Z
New Revision: 5674755cb6f33601e206e57666c3edbb4e73830d
URL: https://github.com/llvm/llvm-project/commit/5674755cb6f33601e206e57666c3edbb4e73830d
DIFF: https://github.com/llvm/llvm-project/commit/5674755cb6f33601e206e57666c3edbb4e73830d.diff
LOG: [DAG] visitMUL - cleanup pattern matchers to use m_Shl and (commutative) m_Mul directly (#190339)
Based on feedback on #190215
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index d26300f0b4c24..70d48895a47bf 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -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);
}
}
More information about the llvm-commits
mailing list