[PATCH] D137142: [WIP] DivergenceAnalysis: Infer uniformity from assume calls

Simon Moll via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 12 03:25:47 PDT 2023


simoll added a comment.

In D137142#4072601 <https://reviews.llvm.org/D137142#4072601>, @nhaehnle wrote:

> In D137142#4051045 <https://reviews.llvm.org/D137142#4051045>, @simoll wrote:
>
>> In D137142#4046742 <https://reviews.llvm.org/D137142#4046742>, @foad wrote:
>>
>>>> For the DA in isolation, ideally, we'd have something like:
>>>>
>>>>   %Y = llvm.assume.uniform(%X)
>>>>   foo(%Y) ; <- Rewritten to use %Y instead of %X.
>>>
>>> This is roughly what the target-specific @llvm.amdgcn.readfirstlane does today, and some frontends do use it to assert and/or enforce uniformity of particular values. There is some sublety about exactly what it means (or exactly what @llvm.assume.uniform //should// mean): Read the first active lane? Read an arbitrary active lane? Undefined/poison if active lanes do not all have the same value?
>>
>> Read all active lanes. The intrinsic only tells us that we can assume uniformity among the active lanes in each instance, it could not be used to enforce it. Not so sure about the values on inactive lanes, I'd say it simply passes through the incoming values.. you may just want poison here though..
>
> We do need to say what happens if the assumptions is wrong. I believe at a minimum we need to say that the result is poison, because of what happens when the result feeds into a conditional branch: divergence analysis uses the assumption, which can affect codegen. So UB on that branch if the assumption is wrong seems like the minimum we need.
>
> Though immediate UB is a legitimate alternative, since it would allow us to replace other uses of %X by %Y.

.. and by extension you can take the control conditions of the call as pre-conditions whereas if it's 'just' `poison` you can only do that for the instructions that actually trigger ub upon poison. You may want to turn the pre-condition into an explicit parameter, as in:

`%y = llvm.assume.uniform(%X, %mask)` <-- triggers immediate UB where %X is not uniform among the threads that actively execute this in lock-step and where %mask is true.

You are then free to rewrite uses of `%X` into uses of `%Y` to improve DA precision.


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

https://reviews.llvm.org/D137142



More information about the llvm-commits mailing list