[llvm] [RISCV] Optimize divide by constant for VP intrinsics (PR #125991)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 5 20:00:27 PST 2025


================
@@ -27219,6 +27280,268 @@ SDValue DAGCombiner::visitVP_FSUB(SDNode *N) {
   return SDValue();
 }
 
+SDValue DAGCombiner::BuildVPUDIV(SDNode *N) {
+  // when optimising for minimum size, we don't want to expand a div to a mul
+  // and a shift.
+  if (DAG.getMachineFunction().getFunction().hasMinSize())
+    return SDValue();
+
+  SmallVector<SDNode *, 8> Built;
+  if (SDValue S = TLI.BuildVPUDIV(N, DAG, LegalOperations, Built)) {
+    for (SDNode *N : Built)
+      AddToWorklist(N);
+    return S;
+  }
+
+  return SDValue();
+}
+
+/// Given an ISD::VP_SDIV node expressing a divide by constant, return
+/// a DAG expression to select that will generate the same value by multiplying
+/// by a magic number.
+/// Ref: "Hacker's Delight" or "The PowerPC Compiler Writer's Guide".
----------------
wangpc-pp wrote:

IIUC, the logic is the same as the non-VP. Can we somehow reduce the duplication?

https://github.com/llvm/llvm-project/pull/125991


More information about the llvm-commits mailing list