[Mlir-commits] [clang] [llvm] [mlir] [AMDGPU] Implement AsyncMark Stages (PR #220442)

Krzysztof Drewniak llvmlistbot at llvm.org
Tue Oct 13 11:46:04 PDT 2026


================
@@ -219,44 +348,49 @@ examined at `Y`.
 
 ```c++
 void bar() {
-  asyncmark();       // B
-  asyncmark();       // C
-  ...                // no asyncmark()
-  wait.asyncmark(0); // Y
+  asyncmark(0);         // B
+  asyncmark(0);         // C
+  ...                   // no asyncmark()
+  wait.asyncmark(0, 0); // Y
   ...
-  wait.asyncmark(1); // D
+  wait.asyncmark(1, 0); // D
 }
 ```
 
 After inlining, both `B` and `C` are *completed-at* `Y`.
 
 ### Optimization
 
-The implementation may eliminate asyncmark/wait intrinsics in the following
-cases. These are just examples and not meant to be an exhaustive list.
+The implementation may eliminate/modify asyncmark/wait intrinsics in the
+following cases. These are just examples and not meant to be an exhaustive list.
 
-1. An `asyncmark` operation which remains in the current sequence along every
+1. An `asyncmark` operation which remains in a current sequence along every
    path that reaches the function exit.
 
    ```c++
    void foo() {
      ...
-     asyncmark();       // X
-     ...                // no wait.asyncmark()
+     asyncmark(0);         // X
+     ...                   // no wait.asyncmark()
    }
    ```
 
-   Here, `X` can be eliminated.
+   Here, the zero mask names every stage, and each independent mark remains, so
+   the entire mark `X` can be eliminated. If only some sequences qualified, then
+   the `asyncmark` operation could be modified to remove just those stages from
+   its mask.
 
 2. A `wait.asyncmark` which sees an empty sequence of asyncmarks along every
    path that reaches it.
 
    ```c++
    void foo() {
-     ...                // no asyncmark()
-     wait.asyncmark(0); // Y
+     ...                   // no asyncmark()
+     wait.asyncmark(0, 0); // Y
      ...
    }
    ```
 
-   Here, `Y` can be eliminated.
+   Here, as with `X` above, every sequence qualifies, so `Y` can be eliminated.
+   If only some sequences qualified, the `wait.asyncmark` could be modified to
+   only wait for the relevant stages.
----------------
krzysz00 wrote:

Let's go ahead and add a rule - and example - that bits in the mask that don't refer to any instruction can be removed. 
Ex.
```
global_load_async_to_lds
asyncmark(0)
```
to
```
global_load_async_to_lds
asyncmark(ASYNC_LOAD_LDS)
```
is a valid program refinement (please ignore me spelling the stage names wrong)

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


More information about the Mlir-commits mailing list