[clang] [llvm] [mlir] [AMDGPU] Introduce waitcounter padding builtin/intrinsic (PR #243204)

Dan Zimmerman via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 16:49:02 PST 2026


danzimm wrote:

I spent the day mulling over (and experimenting with changes to address) all the feedback. Thanks everyone for the discussion so far. Firstly, I agree with removing `count`, so this PR has a decent change coming one way or another. I want to give a quick summary of where we're at to keep things progressing. I think there are 6 proposals here:
- An annotation on the load statement, e.g. `llvm.maskedload(...) !amdgpu.balance.waits !{}`
- An annotation on branches
- `__builtin_amdgcn_pad_waitcnt` without exposing `count`
- `__builtin_amdgcn_pad_waitcnts_across_cf`
- `asyncmark(PAD)`
- Something like https://github.com/llvm/llvm-project/pull/239000
  - Though, this would need expansion to gfx942/950 (wider waves, `global_load_lds`-- this is a quick assessment, not total) and `ds_*` operations (to support the second bullet below)

And there are a couple of design goals that I had in mind:
- __Reduced padding__: While not mandatory, allowing the user to pad e.g. only one of the loads in a branch would be useful. Originally I enabled that via `count`, but e.g. the predicated loads, `asyncmark(PAD)`, and load statement annotations allow reduction without explicitly passing `count`.
- __Wait counter flexibility__: As of this PR only VMcnt is supported, but I have a small follow up planned (once we settle on design) to pad DScnt with `ds_nop`. This is automatic from the annotation and predication strategies. The other designs I'll need help deciding on how to differentiate between the counters.
- __User/frontend driven__: It's unclear what heuristic exists to always enable this optimization. I'd like to start with one of the above designs first.

Lastly, a single constraint:
- __Lowering after StructurizeCFG__: emitting `buffer_inv` needs to happen after `StructurizeCFG`, see [the diagram here](https://github.com/llvm/llvm-project/pull/243204#discussion_r4616274121) for an explanation. To guarantee nothing happens to the `buffer_inv` before SIInsertWaitcnt, I think we should emit them during said pass, just before any waits are inserted.

---

After thinking this through and digesting the above I'd opt for @krzysz00 / @Pierre-vh's annotation idea(s). I originally assumed this would be quite difficult. Instead of assuming, I'll put together a separate PR so we can concretize how complicated that will be.

I think `__builtin_amdgcn_pad_waitcnts_across_cf` is ruled out by the constraint above, unless there's another implementation strategy that gets around how StructurizeCFG lowers conditionals.

This leaves us with
- `__builtin_amdgcn_pad_waitcnt` without exposing `count`
- `asyncmark(PAD)`
- Something like https://github.com/llvm/llvm-project/pull/239000

The last idea seems neat, but I suspect it has a lot of unexpected subtleties and would require a lot more development to get us any wins (beyond the concrete things I mention above, we'd need to change user/frontend code to use the new predicated ops). Consequently I think we should pass on this for now.

The first two are similar, but I lean towards `asyncmark(PAD)`, since, if the user _isn't_ using asyncmarks, then they _are_ emitting their own `s_waitcnt`, in which case they should manage padding/relaxation themselves.

So my opinion is:
```
if (annotations aren't hard) then go with annotations
else asyncmark(PAD)
```

How does that sound to everyone?

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


More information about the cfe-commits mailing list