This is an archive of the discontinued LLVM Phabricator instance.

Prevent LICM and machineLICM from hoisting convergent operations
ClosedPublic

Authored by xiaoqing_wu on Oct 28 2020, 6:13 PM.

Details

Summary

Results of convergent operations are implicitly affected by the enclosing control flows and should not be hoisted out of arbitrary loops.

Diff Detail

Event Timeline

xiaoqing_wu created this revision.Oct 28 2020, 6:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2020, 6:13 PM
xiaoqing_wu requested review of this revision.Oct 28 2020, 6:13 PM
foad added a subscriber: foad.

Results of convergent operations are implicitly affected by the enclosing control flows and should not be hoisted out of arbitrary loops.

I thought it was OK to hoist them out of loops, but not to sink them into loops? The langref says they "should not be made control-dependent on additional values".

This is allowed by the current definition. See D85603

Results of convergent operations are implicitly affected by the enclosing control flows and should not be hoisted out of arbitrary loops.

I thought it was OK to hoist them out of loops, but not to sink them into loops? The langref says they "should not be made control-dependent on additional values".

In practice, convergent attribute has been used on operations that involve inter-thread communication which results are implicitly affected by the enclosing control flows. This was pointed out in the proposal in https://reviews.llvm.org/D85603. The definition in the current langref doesn't reflect how the attribute is used.

This is allowed by the current definition. See D85603

D85603 requires changes to IR to model the dependency of convergent operations on their enclosing control flows.
The change in this review solves a different problem, it is to prevent hoisting with the existing IR.

Hi @foad, hi @arsenm

This is allowed by the current definition. See D85603

I was gong to say that @xiaoqing_wu's patch looks good to me, but I didn't think this was allowed by the current definition, but you're right it looks like it is.
Now, in practice is this something that works for you guys?

I would rather that we fix that asap than pinning that on the new convergence revamp, but if the current definition is okay for some users, I guess we'll have to explore a more target specific way to describe what is and what is not okay to hoist.

What do you think?

Cheers,
-Quentin

Hi @foad, hi @arsenm

This is allowed by the current definition. See D85603

I was gong to say that @xiaoqing_wu's patch looks good to me, but I didn't think this was allowed by the current definition, but you're right it looks like it is.
Now, in practice is this something that works for you guys?

I would rather that we fix that asap than pinning that on the new convergence revamp, but if the current definition is okay for some users, I guess we'll have to explore a more target specific way to describe what is and what is not okay to hoist.

What do you think?

Cheers,
-Quentin

This moves in the more conservative direction more in line with the new definition. It's good for some convergent cases, but not all. For the machine level, I don't think we have an answer for the equivalent of the convergence operands yet.

llvm/lib/Transforms/Scalar/LICM.cpp
1167

isConvergent instead of directly checking the attribute

Changed LICM to call Function::isConvergent() method.

arsenm accepted this revision.Nov 4 2020, 5:25 PM
This revision is now accepted and ready to land.Nov 4 2020, 5:25 PM

@nhaehnle Does the change look good to you?

@foad Please let me know if you have other questions or concerns regarding the change. Thanks.

foad added a comment.Nov 5 2020, 2:05 AM

@foad Please let me know if you have other questions or concerns regarding the change. Thanks.

I think it could at least do with a comment explaining that LICM is being more conservative than the documented meaning of "convergent".

Added a comment on why convergent instructions should not be hoisted or sunk in LICM and machineLICM.

xiaoqing_wu marked an inline comment as done.Nov 5 2020, 11:12 AM

I think it could at least do with a comment explaining that LICM is being more conservative than the documented meaning of "convergent".

Added some comments.