[llvm] [AMDGPU][CodeGen] Do not rematerialize divergent registers with convergent users (PR #222322)
Lucas Ramirez via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 08:37:39 PDT 2026
lucas-rami wrote:
> Sorry, let me be more specific, by dropping the flag I was wondering if at the LLVM IR the definition has the convergent flag but we somehow lost it when we lower to Machine IR and that's the reason of the bug.
Ah, understood. I will look at the LLIR for the miscompile motivating this fix and verify that no convergent flag was spuriously dropped.
> It shouldn't be legal to move %candidate past the redef of $exec. I don't think it's technically a convergent flag issue, although we could argue that %candidate should be tagged convergent.
Why do we ignore the redef of $exec?
In the "common case" where all uses of the register we wish to rematerialize are divergent it should always be ok to rematerialize inside the scheduling region / block in which all the uses are. In those cases the rematerialized def and uses would fall under the same EXEC mask. So I think we can safely ignore any change to `$exec` in such cases, which is what I have been doing in all cases so far.
When at least one user is convergent, the "different basic block check" is a conservative way of checking whether the EXEC mask could be different between the original and rematerialized def positions.
https://github.com/llvm/llvm-project/pull/222322/changes#diff-0cc602cd384aebd0894c4e02f293602abf32a93d143d90269b4eb4b20cfdc8bfR1610-R1615
https://github.com/llvm/llvm-project/pull/222322
More information about the llvm-commits
mailing list