[llvm] [AMDGPU] Add intrinsic readanylane (PR #115696)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 12 01:07:20 PST 2024
jayfoad wrote:
> I would say let's say it clearly that readanylane is defined only if the input is uniform when defined and at the use of readanylane call. We really want the intrinsic to be not convergent to allow related middle-end optimizations.
I'm not comfortable with saying "the input is uniform _when defined_". The problem is with code like this:
```
x = uniform_def();
y = divergent_def();
if (x == y) {
...
}
```
Inside the body of the `if`, generic optimizations should be allowed to replace uses of `x` with `y` and vice versa. But if they replace `readanylane(x)` with `readanylane(y)` then that would break the "uniform when defined" condition.
I don't have a good example of an optimization that actually does this, but I do think they should be allowed to do this.
> btw, I think for the existing uniformity analysis, we can say that: "if a value is uniform at use, then it should be uniform at define", right? We only have the case that a value is defined uniform but divergent at its use currently.
Yes I think that's correct, currently.
> Can this be solved with an attribute instead?
I'm not sure how that would work. We want to apply this to a specific IR `Use`, or to an IR `Value` at a specific point in the CFG. The use case is quite similar to the existing `@llvm.assume` intrinsic.
> If we do need an intrinsic, we should stop comparing it with readfirstlane, and just focus on what readanylane means.
Yeah. I would define it something like "if the argument is uniform, return that value, otherwise the result is undefined" with an explanatory note saying why you would want to use it.
> Would it be correct to rename it to something like "assumeuniform"?
I guess so. Personally I like the name `readanylane`, but that might be because I came up with it :-)
> Does this provide information that can be propagated backwards when initializing uniformity analysis?
Yes, if UA did any backwards propagation then I think this could be a good thing to propagate backwards from.
https://github.com/llvm/llvm-project/pull/115696
More information about the llvm-commits
mailing list