[PATCH] D68994: [RFC] Redefine `convergent` in terms of dynamic instances

Simon Moll via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 29 09:11:51 PDT 2019


simoll added inline comments.


================
Comment at: llvm/docs/DynamicInstances.rst:229
+
+  void @llvm.convergence.point(token %anchor) convergent readnone
+
----------------
nhaehnle wrote:
> arsenm wrote:
> > I don't fully understand what the 'point' of this one is. What is the point of ensuring nonreconvergence? Which real example does this correspond to?
> It allows us to mark regions of code that are semantically part of a loop for the purposes of convergence even when they're not part of the loop as far as loop analysis is concerned. This applies to high-level code such as the following:
> ```
> int divergent_key = ...;
> int v = ...;
> int sum;
> for (;;;) {
>   tok = @llvm.convergence.anchor()
>   int uniform_key = readfirstlane(divergent_key);
>   if (uniform_key == divergent_key) {
>     sum = subgroup_reduce_add(v);
>     @llvm.convergence.point(tok)
>     break;
>   }
> }
> ```
> The point indicates that no reconvergence should happen for the execution of the reduce operation (or in a sense, that the reduce operation should not be moved out of the loop).
> 
> Points are in some sense redundant, as the code above could be equivalently rewritten as:
> ```
> int divergent_key = ...;
> int v = ...;
> int sum;
> for (;;;) {
>   tok = @llvm.convergence.anchor()
>   int uniform_key = readfirstlane(divergent_key);
>   if (uniform_key == divergent_key) {
>     sum = subgroup_reduce_add(v);
>   }
>   @llvm.convergence.join(tok)
>   if (uniform_key == divergent_key)
>     break;
> }
> ```
> Though that reformulation loses some information about control-flow, in particular it leads to more conservative live ranges.
Couldn't you align the conceptual convergence point with the loop structure by adding a `@llvm.always.true` intrinsic like so:


```
int divergent_key = ...;
int v = ...;
int sum;
for (;;;) {
  int uniform_key = readfirstlane(divergent_key);
  if (uniform_key == divergent_key) {
    sum = subgroup_reduce_add(v);
    %we.know.its.true = call @llvm.always.true()
   br i1 %we.know.its.true, %loopExitBlock, %nextBlockInTheLoop
  }
}
```

That way you do not need the intrinsic and the DA/SDA already assume that threads only synchronize at (`LoopInfo`) loop exits.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68994/new/

https://reviews.llvm.org/D68994





More information about the llvm-commits mailing list