[PATCH] D30921: SimplifyCFG: SinkThenElseCode shouldn't sink convergent functions

Justin Lebar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 18:02:41 PDT 2017


jlebar added a comment.

In https://reviews.llvm.org/D30921#700043, @arsenm wrote:

> I think this is a legal transformation. For example if you have a barrier like this with a divergent condition, the source program is broken. You can infer from this that %cond is a uniform condition


I don't think it's correct to infer that if you call a convergent function from within a branch that the branch is uniform.  For one thing, the function may not actually call a barrier function -- "convergent" is a *restriction* on the optimizer, but it's not a promise to the optimizer that a function does anything in particular.  For example, in CUDA code clang marks all functions as convergent, and then relies on LLVM to remove the attr where it can prove that the function is not convergent.  But this analysis is not complete (I can provide examples if this is needed, but one obvious case is, all inline asm is opaque and assumed to be convergent).

Nonetheless I agree with Matt that this optimization is correct, just for a different reason.  As spec'ed in the langref, you cannot *add* control-flow dependencies to calls to convergent functions.  You are allowed to *remove* dependencies, however.  This transformation does exactly that.


https://reviews.llvm.org/D30921





More information about the llvm-commits mailing list