<div dir="ltr">Would getShiftAmountConstant be better?<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, May 18, 2023 at 11:58 AM Amaury Séchet via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Author: Amaury Séchet<br>
Date: 2023-05-18T18:58:07Z<br>
New Revision: 87bf2bff0561c1cfb6e3864f194088242d06030f<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/87bf2bff0561c1cfb6e3864f194088242d06030f" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/87bf2bff0561c1cfb6e3864f194088242d06030f</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/87bf2bff0561c1cfb6e3864f194088242d06030f.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/87bf2bff0561c1cfb6e3864f194088242d06030f.diff</a><br>
<br>
LOG: [NFC][DAG] Simplify a giant expression in visitMul.<br>
<br>
Added: <br>
<br>
<br>
Modified: <br>
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
index 75b6d8630f365..7173f52b72846 100644<br>
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
@@ -4288,13 +4288,14 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {<br>
   // fold (mul x, -(1 << c)) -> -(x << c) or (-x) << c<br>
   if (N1IsConst && !N1IsOpaqueConst && ConstValue1.isNegatedPowerOf2()) {<br>
     unsigned Log2Val = (-ConstValue1).logBase2();<br>
+    EVT ShiftVT = getShiftAmountTy(N0.getValueType());<br>
+<br>
     // FIXME: If the input is something that is easily negated (e.g. a<br>
     // single-use add), we should put the negate there.<br>
     return DAG.getNode(ISD::SUB, DL, VT,<br>
                        DAG.getConstant(0, DL, VT),<br>
                        DAG.getNode(ISD::SHL, DL, VT, N0,<br>
-                            DAG.getConstant(Log2Val, DL,<br>
-                                      getShiftAmountTy(N0.getValueType()))));<br>
+                            DAG.getConstant(Log2Val, DL, ShiftVT)));<br>
   }<br>
<br>
   // Attempt to reuse an existing umul_lohi/smul_lohi node, but only if the<br>
<br>
diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp<br>
index c823792b611e1..97119e8be62d5 100644<br>
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp<br>
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp<br>
@@ -15893,7 +15893,7 @@ bool RISCVTargetLowering::decomposeMulByConstant(LLVMContext &Context, EVT VT,<br>
       Subtarget.hasStdExtM() || Subtarget.hasStdExtZmmul();<br>
   if (!VT.isScalarInteger())<br>
     return false;<br>
-  <br>
+<br>
   // Omit the optimization if the sub target has the M extension and the data<br>
   // size exceeds XLen.<br>
   if (HasExtMOrZmmul && VT.getSizeInBits() > Subtarget.getXLen())<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>