This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPUUnifyDivergentExitNodes] Add NewPM support
ClosedPublic

Authored by gandhi21299 on Jan 9 2023, 10:05 PM.

Details

Summary

Meanwhile, use UniformityAnalysis instead of LegacyDivergenceAnalysis to collect divergence info.

Diff Detail

Event Timeline

gandhi21299 created this revision.Jan 9 2023, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 10:05 PM
gandhi21299 requested review of this revision.Jan 9 2023, 10:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 9 2023, 10:05 PM
gandhi21299 retitled this revision from PATCH to [AMDGPU] Add NewPM support to AMDGPUUnifyDivergentExitNodes pass.Jan 9 2023, 10:07 PM
  • added checks for the opt command in si-annotate-nested-control-flow.ll
  • applied clang-format
gandhi21299 added a subscriber: Restricted Project.
arsenm added inline comments.Jan 10 2023, 5:58 AM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

Not sure why you really need to change this, but the function should probably be a template argument. Is DA just missing a layer to present the PM independent analysis?

gandhi21299 added inline comments.Jan 10 2023, 9:21 AM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

The LegacyPM version depends on LegacyDivergenceAnalysis info whereas the NewPM version of this pass depends on DivergenceInfo.

arsenm added inline comments.Jan 10 2023, 9:41 AM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

There should be a common logic DivergenceInfo that both pass versions export

gandhi21299 updated this revision to Diff 487868.EditedJan 10 2023, 10:12 AM
  • isUniformlyReached now accepts a template argument instead of a std::function to allow both pass managers to use their corresponding DivergenceAnalysis info.
  • DivergenceAnalysis::isUniform(Value &V) -> DivergenceAnalysis::isUniform(Value *V)

Rebased and applied clang-format

  • Rebased and initialized TTI = nullptr
gandhi21299 added inline comments.Jan 12 2023, 11:15 AM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

How do these changes look @arsenm ?

arsenm added inline comments.Jan 12 2023, 11:57 AM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

I'm still confused. LegacyDivergenceAnalysis and DivergenceAnalysis/DivergenceInfo are two *different* analyses. LegacyDivergenceAnalysis is *not* the Legacy pass manager version of DivergenceAnalysis. New pass manager shouldn't invisibly switch the analysis used. I think LegacyDivergenceAnalysis needs to be ported to new PM first

gandhi21299 added inline comments.Jan 14 2023, 2:54 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

Ahh I guess I got confused with the names as well. Sure, I will port LegacyDivergenceAnalysis to newPM first.

gandhi21299 planned changes to this revision.Jan 14 2023, 3:01 PM

Added missing newline

At this point, there are three analyses as follows:

  1. LegacyDA is actually wrong, but useful in some cases involving irreducible control flow.
  2. GpuDA is correct, but treats irreducible control flow very conservatively.
  3. UniformityAnalysis is both correct and better at irreducible control flow.

Note that in almost every use on AMDGPU, LegacyDA simply acts as a wrapper for GpuDA.

Since this is fresh work, why not just go straight to UniformityAnalysis? I would definitely recommend that because not only does go straight to new stuff, it also avoids the unnecessary template. This would be a good time to use the new analysis. And if issues crop up that can't be fixed, then we should fall back no further than GpuDA, and unify their exposed Info objects along the way.

llvm/include/llvm/Analysis/DivergenceAnalysis.h
177

Why is this change necessary? The point of accepting a reference is to indicate that nullptr is not expected inside the function.

sameerds added inline comments.Jan 22 2023, 11:31 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120–121

No! Don't even try. It was considered and discarded long ago.

337

As already noted, this legacy is not related to the pass manager. Just use the same DA in both.

tsymalla added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
120

Can you give a more meaningful name to the template argument? For instance, DivergenceAnalysisType?

gandhi21299 planned changes to this revision.Jan 24 2023, 10:52 AM
ruiling added a subscriber: ruiling.Feb 2 2023, 7:01 AM
ruiling added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
190–192

I think you just removed this accidentally.

I will create a new patch to replace LegacyDivergenceAnalysis with Uniformity analysis, unless it's too early to do so.

  • Rebased with uniformity analysis dependency
  • Removed template param
  • Refactors
gandhi21299 marked 5 inline comments as done.Mar 13 2023, 8:05 PM
gandhi21299 retitled this revision from [AMDGPU] Add NewPM support to AMDGPUUnifyDivergentExitNodes pass to [AMDGPUUnifyDivergentExitNodes] Add NewPM support.Mar 13 2023, 9:39 PM
sameerds added inline comments.Mar 13 2023, 9:53 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
187–194

Either declare parameters as references, or implement checks for nullptr in the function body. Also, can any of these be const?

190–192

Was this comment addressed?

335–336

If you know that a variable cannot be nullptr, it is preferable to declare it as a reference rather than a pointer. It can be converted into a pointer at the point where some function expects a pointer. For example, the call below can be "whatever.run(&DT, &PDT, UA)".

gandhi21299 added inline comments.Mar 13 2023, 10:50 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
190–192

yup, I moved it under AMDGPUUnifyDivergentExitNodesImpl::run(..)

gandhi21299 added inline comments.Mar 13 2023, 10:53 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
187–194

DominatorTree may be updated but PostDominatorTree and UniformityInfo are preserved.

  • Addressed reviewer comments
foad added a comment.Mar 14 2023, 2:53 AM

The commit message should make it clear that you're also changing it to use UniformityAnalysis instead of (Legacy?)DivergenceAnalysis.

llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.h
57 ↗(On Diff #504953)

It looks like only this class needs to be declared in the .h file. The others could stay in the .cpp file.

gandhi21299 marked 7 inline comments as done.Mar 14 2023, 8:38 AM
gandhi21299 edited the summary of this revision. (Show Details)Mar 14 2023, 10:56 AM
  • Move AMDGPUUnifyDivergentExitNodesImpl and AMDGPUUnifyDivergentExitNodes classes to the source file from the header file.
  • Move includes from header to source
  • do not need to include PassManager
  • TTI should be private instead of protected in the Impl
sameerds accepted this revision.Mar 14 2023, 11:01 PM

LGTM, but wait for a day to let other reviewers comment.

This revision is now accepted and ready to land.Mar 14 2023, 11:01 PM

Internal CI passed.

arsenm accepted this revision.Mar 15 2023, 3:56 PM
This revision was automatically updated to reflect the committed changes.
vitalybuka reopened this revision.Mar 16 2023, 7:02 PM
vitalybuka added a subscriber: vitalybuka.
vitalybuka added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
340
This revision is now accepted and ready to land.Mar 16 2023, 7:02 PM

Impl::run(..) now accepts DominatorTree* instead of DominatorTree& to avoid undefined behavior due to the possibility of DT == nullptr.

gandhi21299 added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
340

Great catch! How does it look now?

arsenm added inline comments.Mar 24 2023, 1:17 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
186–187

When is DT null but PDT won't be?

gandhi21299 added inline comments.Mar 24 2023, 1:28 PM
llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp
186–187

This pass depends on PDT so it can never be null. DT may be null if it does not need to be preserved, which is specified by -simplifycfg-require-and-preserve-domtree.

arsenm accepted this revision.Mar 24 2023, 7:21 PM
This revision was automatically updated to reflect the committed changes.