[llvm] [LLVM][DAGCombiner] fold (shl (X * vscale(C0)), C1) -> (X * vscale(C0 << C1)). (PR #150651)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 31 06:31:38 PDT 2025
================
@@ -10615,6 +10615,15 @@ SDValue DAGCombiner::visitSHL(SDNode *N) {
return DAG.getVScale(DL, VT, C0 << C1);
}
+ SDValue X;
+ APInt VS0;
+
+ // fold (shl (X * vscale(VS0)), C1) -> (X * vscale(VS0 << C1))
+ if (N1C && sd_match(N0, m_Mul(m_Value(X), m_VScale(m_ConstInt(VS0))))) {
+ SDValue VScale = DAG.getVScale(DL, VT, VS0 << N1C->getAPIntValue());
+ return DAG.getNode(ISD::MUL, DL, VT, X, VScale);
----------------
paulwalker-arm wrote:
It looks like NoUnsignedWrap can be preserved, but only when both the shift and multiply have it set. I don't know of any easy way to protect the code but the commit contains an alive2 link to show its validity.
https://github.com/llvm/llvm-project/pull/150651
More information about the llvm-commits
mailing list