This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Check atomics aliasing in the clobbering annotation
ClosedPublic

Authored by rampitec on Jan 31 2022, 3:18 PM.

Details

Summary

MemorySSA considers any atomic a def to any operation it dominates
just like a barrier or fence. That is correct from memory state
perspective, but not required for the no-clobber metadata since
we are not using it for reordering. Skip such atomics during the
scan just like a barrier if it does not alias with the load.

Diff Detail

Event Timeline

rampitec created this revision.Jan 31 2022, 3:18 PM
rampitec requested review of this revision.Jan 31 2022, 3:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2022, 3:18 PM
Herald added a subscriber: wdng. · View Herald Transcript
arsenm added inline comments.Jan 31 2022, 3:22 PM
llvm/test/CodeGen/AMDGPU/noclobber-barrier.ll
452

volatile makes this test stricter, should probably not have it

505

Ditto

601

Is there already a test that verifies load atomic is not optimizable?

rampitec updated this revision to Diff 404756.Jan 31 2022, 3:41 PM
rampitec marked 2 inline comments as done.

Removed volatile from atomics in tests.

rampitec marked an inline comment as done.Jan 31 2022, 3:42 PM
rampitec added inline comments.
llvm/test/CodeGen/AMDGPU/noclobber-barrier.ll
601

Yes, clobber_by_atomic_load in this file.

arsenm accepted this revision.Jan 31 2022, 3:44 PM
arsenm added inline comments.
llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
141

Typo unversal

This revision is now accepted and ready to land.Jan 31 2022, 3:44 PM
rampitec updated this revision to Diff 404758.Jan 31 2022, 3:46 PM
rampitec marked 2 inline comments as done.

Fixed typo in the comment.

rampitec updated this revision to Diff 404767.Jan 31 2022, 4:41 PM

Fixed not calling getClobberingMemoryAccess, it was gathering more defs for inspection than needed. Added test for this case.

arsenm accepted this revision.Jan 31 2022, 6:37 PM
arsenm added inline comments.
llvm/test/CodeGen/AMDGPU/noclobber-barrier.ll
623

No volatile

foad added inline comments.Feb 1 2022, 2:12 AM
llvm/lib/Target/AMDGPU/AMDGPUAnnotateUniformValues.cpp
52

Should add an addUsedIfAvailable call for AA here. But I think MemorySSA already requires it, so you could make it a hard requirement here too?

foad added a comment.Feb 1 2022, 6:02 AM

MemorySSA considers any atomic a def to any operation it dominates

I guess this is because of the problem described by the TODO in MemorySSA::createNewAccess:

// The isOrdered check is used to ensure that volatiles end up as defs
// (atomics end up as ModRef right now anyway).  Until we separate the
// ordering chain from the memory chain, this enables people to see at least
// some relative ordering to volatiles.  Note that getClobberingMemoryAccess
// will still give an answer that bypasses other volatile loads.  TODO:
// Separate memory aliasing and ordering into two different chains so that
// we can precisely represent both "what memory will this read/write/is
// clobbered by" and "what instructions can I move this past".

?

Maybe a cleaner way to handle this would be to implement a new MemorySSAWalker subclass where getClobberingMemoryAccess(I) ignores ordering, and only returns a def that mayAlias I. But I suppose that's more work.

rampitec marked an inline comment as done.Feb 1 2022, 11:31 AM

MemorySSA considers any atomic a def to any operation it dominates

I guess this is because of the problem described by the TODO in MemorySSA::createNewAccess:

// The isOrdered check is used to ensure that volatiles end up as defs
// (atomics end up as ModRef right now anyway).  Until we separate the
// ordering chain from the memory chain, this enables people to see at least
// some relative ordering to volatiles.  Note that getClobberingMemoryAccess
// will still give an answer that bypasses other volatile loads.  TODO:
// Separate memory aliasing and ordering into two different chains so that
// we can precisely represent both "what memory will this read/write/is
// clobbered by" and "what instructions can I move this past".

?

Maybe a cleaner way to handle this would be to implement a new MemorySSAWalker subclass where getClobberingMemoryAccess(I) ignores ordering, and only returns a def that mayAlias I. But I suppose that's more work.

Yes, that's the issue. This is how ordering is modeled.

rampitec updated this revision to Diff 405025.Feb 1 2022, 11:56 AM
rampitec marked an inline comment as done.
  • Added AA as required analysis.
  • Dropped volatile in the test.
rampitec updated this revision to Diff 405044.Feb 1 2022, 12:14 PM

Fixed rebase artifact.

This revision was landed with ongoing or failed builds.Feb 1 2022, 12:33 PM
This revision was automatically updated to reflect the committed changes.