This is an archive of the discontinued LLVM Phabricator instance.

[Local] Consider atomic loads from constant global as dead
ClosedPublic

Authored by nikic on Apr 22 2022, 2:19 AM.

Details

Summary

Per the guidance in https://llvm.org/docs/Atomics.html#atomics-and-ir-optimization, an atomic load from a constant global can be dropped, as it is not observable. Any write to the constant global would be UB.

IPSCCP will already drop such loads, but the main helper in Local doesn't recognize this currently. This is motivated by D118387.

Diff Detail

Event Timeline

nikic created this revision.Apr 22 2022, 2:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 2:19 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Apr 22 2022, 2:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2022, 2:19 AM
fhahn accepted this revision.Apr 22 2022, 2:40 AM

LGTM, thanks!

llvm/lib/Transforms/Utils/Local.cpp
503

nit: can be removed, unless they are volatile.?

This revision is now accepted and ready to land.Apr 22 2022, 2:40 AM
nikic abandoned this revision.Apr 22 2022, 5:24 AM

Abandoning this in favor of D124247, which implements a more general version of this. The "from constant" bit was a red herring. Loading from a constant allows us to determine the result and remove uses, but we can remove any atomic load as long as it has no uses.

nikic reclaimed this revision.Apr 26 2022, 9:31 AM

Reopening this, as it looks like D124247 is not correct in the general case.

This revision is now accepted and ready to land.Apr 26 2022, 9:31 AM
nikic edited the summary of this revision. (Show Details)Apr 27 2022, 1:15 AM
nikic updated this revision to Diff 426048.Apr 29 2022, 7:08 AM
nikic marked an inline comment as done.

Update PowerPC test to avoid optimizing away atomic load.

This revision was landed with ongoing or failed builds.May 2 2022, 1:53 AM
This revision was automatically updated to reflect the committed changes.