[llvm] [DAG] visitMUL - cleanup pattern matchers to use m_Shl and (commutative) m_Mul directly (PR #190339)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 05:52:21 PDT 2026
https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/190339
Based on feedback on #190215
>From 91316d768e7bc1a8646d04854797a9500bacbd6d Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Fri, 3 Apr 2026 13:51:42 +0100
Subject: [PATCH] [DAG] visitMUL - cleanup pattern matchers to use m_Shl and
(commutative) m_Mul directly
Based on feedback on #190215
---
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 30 ++++++++-----------
1 file changed, 12 insertions(+), 18 deletions(-)
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