This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][Uniformity] Propagate temporal divergence explicitly
ClosedPublic

Authored by sameerds on May 2 2023, 5:50 AM.

Details

Summary

At a cycle C with divergent exits, UA was using a naive traversal of the exiting
edges to locate blocks that may use values defined inside C. But this traversal
fails when it encounters a cycle. This is now replaced with a much simpler
propagation that iterates over every instruction in C and checks any uses that
are outside C. But such an iteration can be expensive when C is very large; the
original strategy may need to be reconsidered if there is a regression in
compilation times.

Also fixed lit tests that should have originally caught the missed propagation
of temporal divergence.

Diff Detail

Event Timeline

sameerds created this revision.May 2 2023, 5:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 5:50 AM
sameerds requested review of this revision.May 2 2023, 5:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 2 2023, 5:50 AM
sameerds added a subscriber: Restricted Project.
foad added inline comments.May 2 2023, 6:06 AM
llvm/include/llvm/ADT/GenericUniformityImpl.h
456–457

Comment should be updated. It doesn't mention I.

846–850

I wonder if there is a quick test you could use to avoid scanning some BBs, e.g. I think if BB does not dominate any edges that exit OuterDivCycle then instructions in BB cannot have any uses outside OuterDivCycle. This should be fairly common because it applies to the body of a simple C "for" loop.

llvm/lib/Analysis/UniformityAnalysis.cpp
79–80

Just iterate over users() instead of uses().

Confirmed that this fixes an issue we observed in an app.

sameerds updated this revision to Diff 521993.May 14 2023, 5:02 AM
  • only examine blocks that dominate an exit.
  • FIXME about narrowing this down to live-out values at each divergent exit.
yassingh added inline comments.
llvm/lib/CodeGen/MachineUniformityAnalysis.cpp
117–136

Is the case described in the summary also triggering for MIR? If yes maybe you can add a relevant test.

sameerds marked 3 inline comments as done.May 14 2023, 11:14 PM
sameerds added inline comments.
llvm/lib/CodeGen/MachineUniformityAnalysis.cpp
117–136

I just tried adding an identical MIR test. Unfortunately, it runs into the problem with SI_LOOP that is being fixed in D150438. I'll add the test to that review.

foad accepted this revision.May 15 2023, 2:24 AM

Looks fine to me, thanks!

llvm/include/llvm/ADT/GenericUniformityImpl.h
817–819

Conceptually you could unify these two cases by looking for blocks B that dominate an exit edge; but I have no idea whether DomTree has good support for querying dominance on CFG edges.

839

Might be cleaner to use any_of?

This revision is now accepted and ready to land.May 15 2023, 2:24 AM
foad added inline comments.May 15 2023, 3:28 AM
llvm/include/llvm/ADT/GenericUniformityImpl.h
818

Nit: say "DefCycle" instead of "C" (which you have not defined)?

This revision was landed with ongoing or failed builds.May 15 2023, 7:48 AM
This revision was automatically updated to reflect the committed changes.
sameerds marked 2 inline comments as done.May 15 2023, 8:01 AM
sameerds added inline comments.
llvm/include/llvm/ADT/GenericUniformityImpl.h
817–819

I had a cursory look. The DominatorTree interface has methods to query edges dominating uses, but none to check for defs dominating edges.