This is an archive of the discontinued LLVM Phabricator instance.

[llvm][GenericUniformity] Prevent assert while calculating temporal divergence
ClosedPublic

Authored by yassingh on Feb 14 2023, 10:02 PM.

Details

Summary

analyzeTemporalDivergence() was missing the check for always-uniform before
evaluating weather an instruction depends on a value defined in the cycle.
Fix for #60638

Diff Detail

Event Timeline

yassingh created this revision.Feb 14 2023, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2023, 10:02 PM
yassingh requested review of this revision.Feb 14 2023, 10:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2023, 10:02 PM
yassingh retitled this revision from [llvm-uniformity-analysis] Fix usesValueFromCycle to [llvm-uniformity-analysis] Fix assert in usesValueFromCycle.Feb 14 2023, 10:06 PM
yassingh edited the summary of this revision. (Show Details)
yassingh added reviewers: sameerds, arsenm, foad.
yassingh retitled this revision from [llvm-uniformity-analysis] Fix assert in usesValueFromCycle to [llvm][GenericUniformity] Prevent assert while calculating temporal divergence .Feb 14 2023, 10:19 PM
yassingh edited the summary of this revision. (Show Details)
foad added a reviewer: Restricted Project.Feb 15 2023, 1:32 AM
foad added inline comments.
llvm/include/llvm/ADT/GenericUniformityImpl.h
814

This is too complicated. Just swap lines 814 and 817.

yassingh updated this revision to Diff 497593.Feb 15 2023, 1:50 AM
yassingh retitled this revision from [llvm][GenericUniformity] Prevent assert while calculating temporal divergence to [llvm][GenericUniformity] Prevent assert while calculating temporal divergence.

Reordered conditions as Jay mentioned

arsenm added inline comments.Feb 15 2023, 3:36 AM
llvm/lib/CodeGen/MachineUniformityAnalysis.cpp
107

Remove dead assert

llvm/test/Analysis/DivergenceAnalysis/AMDGPU/MIR/uses-value-from-cycle.mir
5

Shouldn't need IR section?

138–158

Surely you don't need all these arguments?

sameerds added inline comments.Feb 15 2023, 6:56 AM
llvm/lib/CodeGen/MachineUniformityAnalysis.cpp
108

What does it mean to continue here? Is it true that a physical register cannot be written inside the cycle? A comment explaining why will be useful.

yassingh added inline comments.Feb 16 2023, 4:15 AM
llvm/lib/CodeGen/MachineUniformityAnalysis.cpp
108

Didn't get around to putting a lot of thought into it. Physical register operands need to be handled separately, which might also include sub-cases if it's an exec mask or function parameters/return values, etc. Continue here is just a placeholder until we have a way to deal with them.

llvm/test/Analysis/DivergenceAnalysis/AMDGPU/MIR/uses-value-from-cycle.mir
5

I took the tests from #60638 (extracted the GMIR input that was fed to uniformity analysis). I wasn't able to use @llvm.amdgcn.raw.atomic.buffer.load without including the IR section. Is there a workaround?

sameerds added inline comments.Feb 16 2023, 4:28 AM
llvm/lib/CodeGen/MachineUniformityAnalysis.cpp
108

But if the exact conclusion is not known, then the correct conclusion is to be conservative. For example, it is always safer to assume that a value is divergent rather than assuming that it is uniform. In this particular case, it means that if we don't know whether the physical register was defined inside the cycle, then it is safer to assume that it was, and hence return true. Such a register will then be marked divergent by the caller.

The commit description uses a number "60638" to refer to some issue, but there is no suitable context. If this is a github issue, just putting the whole URL might be better? And do note that this needs to be in the git commit, and not just the review description on this page.

The commit description uses a number "60638" to refer to some issue, but there is no suitable context. If this is a github issue, just putting the whole URL might be better? And do note that this needs to be in the git commit, and not just the review description on this page.

This is the form GitHub recognizes to auto-close the issue

arsenm added inline comments.Feb 16 2023, 5:55 PM
llvm/test/Analysis/DivergenceAnalysis/AMDGPU/MIR/uses-value-from-cycle.mir
5

The intrinsic declaration is broken in some way because it's having an address computed. The reference in SI_PC_ADD_REL_OFFSET indicates this wasn't recognized as an intrinsic.

yassingh updated this revision to Diff 499393.Feb 21 2023, 11:53 PM

Review comments

yassingh marked 2 inline comments as done.Feb 21 2023, 11:58 PM

The commit description uses a number "60638" to refer to some issue, but there is no suitable context. If this is a github issue, just putting the whole URL might be better? And do note that this needs to be in the git commit, and not just the review description on this page.

Will also append issue link to the commit message.

llvm/test/Analysis/DivergenceAnalysis/AMDGPU/MIR/uses-value-from-cycle.mir
5

I didn't realize earlier that @llvm.amdgcn.raw.atomic.buffer.load.i32 is not actually an intrinsic just looks like one, hence appears to be broken.
Considering dropping this test as it's confusing and bloated.

arsenm added inline comments.Feb 22 2023, 3:31 AM
llvm/test/Analysis/DivergenceAnalysis/AMDGPU/MIR/uses-value-from-cycle.mir
5

This must have a test, but simpler

yassingh updated this revision to Diff 500096.Feb 24 2023, 12:25 AM

Simplified test

sameerds accepted this revision.Mar 1 2023, 3:17 AM

The change itself looks okay to me. But please wait for comments on whether the tests are okay.

This revision is now accepted and ready to land.Mar 1 2023, 3:17 AM
foad accepted this revision.Mar 1 2023, 5:53 AM

LGTM.