This is an archive of the discontinued LLVM Phabricator instance.

[DivergenceAnalysis] Add methods for querying divergence at use
ClosedPublic

Authored by foad on Jul 23 2019, 6:48 AM.

Details

Summary

The existing isDivergent(Value) methods query whether a value is
divergent at its definition. However even if a value is uniform at its
definition, a use of it in another basic block can be divergent because
of divergent control flow between the def and the use.

This patch adds new isDivergent(Use) methods to DivergenceAnalysis,
LegacyDivergenceAnalysis and GPUDivergenceAnalysis.

This might allow D63953 or other similar workarounds to be removed.

Diff Detail

Repository
rL LLVM

Event Timeline

foad created this revision.Jul 23 2019, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 23 2019, 6:48 AM

Nice work! It's missing tests though -- I'm not sure if we want to print this additional information in the divergence printer, but definitely a test for the atomic optimizer pass is required.

llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp
204–206 ↗(On Diff #211284)

Please put braces around the for body (multi-line body).

365 ↗(On Diff #211284)

What's the rationale for checking the user here as well?

For example, if the user is a binary operation that is divergent only because the other use is divergent, then I'd expect this function to return false...

foad updated this revision to Diff 211462.Jul 24 2019, 4:07 AM

Address review comments.

Rename the new methods to make it clear that they take a Use. Otherwise,
since there's an implicit conversion from Use to Value*, it's too hard
to be sure which overload you are calling.

Fix an egregious typo in LegacyDivergenceAnalysis::isDivergentUse.

Add a test for the atomic optimizer usage.

foad marked 3 inline comments as done.Jul 24 2019, 4:10 AM

It's missing tests though -- I'm not sure if we want to print this additional information in the divergence printer

Me neither. I'm open to suggestions.

llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp
365 ↗(On Diff #211284)

This was a subtle typo, getUser() instead of get(). Thanks for catching it.

Does this avoid the need to run LCSSA for isel, assuming the DAG switches to checking the use instead of the def?

foad marked an inline comment as done.Jul 24 2019, 9:04 AM

Does this avoid the need to run LCSSA for isel, assuming the DAG switches to checking the use instead of the def?

That's my hope, and that's what I meant by "this might allow D63953 or other similar workarounds to be removed", but I really don't know enough about divergence driven isel to be sure.

nhaehnle accepted this revision.Jul 25 2019, 5:39 AM

I do prefer the explicit isDivergentUse!

To @arsenm 's question: at least for the SelectionDAG, the key is in SITargetLowering::isSDNodeSourceOfDivergence, which calls isDivergent on a value.

The way the SelectionDAG works, we have in our hands at this point a live value that comes into a basic block via a register. This suggests an isDivergentInBB. Would it be possible to do that instead / on top? For the new DA this seems very natural, and for the old DA this seems at least possible by storing a set of divergent (Value, BasicBlock) pairs instead of divergent uses. Alternatively, we'd have to scan the uses for one that lives in the appropriate basic block, which is slow since it means traversing a linked list... or perhaps there are other thoughts on this.

This revision is now accepted and ready to land.Jul 25 2019, 5:39 AM
foad added a comment.Jul 25 2019, 8:14 AM

To @arsenm 's question: at least for the SelectionDAG, the key is in SITargetLowering::isSDNodeSourceOfDivergence, which calls isDivergent on a value.

The way the SelectionDAG works, we have in our hands at this point a live value that comes into a basic block via a register. This suggests an isDivergentInBB.

Is it guaranteed that the basic block does contain a use of the value? If not, I think this will be difficult to implement in LegacyDivergenceAnalysis.

This revision was automatically updated to reflect the committed changes.