[llvm] [OpenMPOpt] Bound indirect-call specialization instead of paying for all of it (PR #219323)

Larry Meadows via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 6 14:50:06 PDT 2026


================
@@ -5830,6 +5911,20 @@ AAFoldRuntimeCall &AAFoldRuntimeCall::createForPosition(const IRPosition &IRP,
   return *AA;
 }
 
+/// Bound the if-cascade AAIndirectCallInfo builds for an indirect call. Device
+/// code routes many parallel regions through a single runtime dispatcher, so a
+/// call site there can see every outlined region in the module; specializing
+/// all of them costs more in code size and compile time than the direct calls
+/// are worth.
+static constexpr unsigned MaxIndirectCallSpecializations = 3;
+
+static bool shouldSpecializeIndirectCallee(Attributor &,
+                                           const AbstractAttribute &,
+                                           CallBase &, Function &,
+                                           unsigned NumAssumedCallees) {
+  return NumAssumedCallees <= MaxIndirectCallSpecializations;
----------------
lfmeadow wrote:

Measured it, and it goes the other way.

The generated module behind the numbers in the description: a 256-entry device
function-pointer table, 2048 dispatch functions holding one indirect call each,
64 target regions. Rebuilt on trunk for gfx90a, then
`opt -disable-verify -passes='openmp-opt,lto<O3>'`, min of 3 runs:

|                                    | cap 3 | no cap |
|------------------------------------|-------|--------|
| LTO pipeline                        | 13.3s | 34.4s  |
| final module, IR lines              | 340k  | 511k   |
| inlined copies of the leaf bodies   | 2306  | 6402   |
| cascade equality tests after openmp-opt | 310 | 499  |

Specialization is what multiplies the inlined copies, not the absence of it:
every arm of the cascade is a direct call the inliner then inlines. Capping
gives 2.8x fewer copies and a third less code, so I can't find a case where it
makes the output worse.

Worth stating explicitly since the description doesn't: trunk pays the `no cap`
column today. `registerAAsForFunction()` seeds `AAIndirectCallInfo`
unconditionally, so this is removing a cost that is already there rather than
bounding one the patch introduces.

The threshold is now `-openmp-opt-max-callees-for-specialization`, so you can
try your downstream case at other values without a rebuild.

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


More information about the llvm-commits mailing list