This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Don't replace unused `atomicrmw xchg` with `atomic store`
ClosedPublic

Authored by qcolombet on Jan 19 2023, 2:23 AM.

Details

Summary

Following the discussion from https://reviews.llvm.org/D141277 and in
particular Ralf Jung's comment at
https://reviews.llvm.org/D141277#inline-1365148, replacing an unused `atomicrmw
xchg` into an atomic store is illegal even for release ordering.

Quoting Connor Horman from the rust lang discussion linked in that comment:
"An acquire operation A only synchronizes-with a release operation R if it
takes its value from R, or any store in the release sequence headed by R, which
is R, followed by the longest continuous sequence of read-modify-write
operations.
A regular store following R in the modification order would break the release
sequence, and if an acquire operation reads that store or something later, then
it loses any synchronization it might have already had."

Diff Detail

Event Timeline

qcolombet created this revision.Jan 19 2023, 2:23 AM
qcolombet requested review of this revision.Jan 19 2023, 2:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 2:23 AM

I agree this optimization should not be performed. Also see https://github.com/llvm/llvm-project/issues/60418 for a counterexample.

nikic accepted this revision.Jan 31 2023, 8:57 AM

LGTM

This revision is now accepted and ready to land.Jan 31 2023, 8:57 AM