[PATCH] D141748: [WoA] Use fences for sequentially consistent stores

Usman Nadeem via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 20:48:50 PST 2023


mnadeem created this revision.
mnadeem added reviewers: efriedma, dmgreen, lenary, john.brawn, t.p.northover.
Herald added subscribers: mstorsjo, hiraditya.
Herald added a project: All.
mnadeem requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LLVM currently uses LDAR/STLR and variants for acquire/release
as well as seq_cst operations. This is fine as long as all code uses
this convention.

Normally LDAR/STLR act as one way barriers but when used in
combination they provide a sequentially consistent model. i.e.
when an LDAR appears after an STLR in program order the STLR
acts as a two way fence and the store will be observed before
the load.

The problem is that normal loads (unlike ldar), when they appear
after the STLR can be observed before STLR (if my understanding
is correct). Possibly providing weaker than expected guarantees if
they are used for ordered atomic operations.

Unfortunately in Microsoft Visual Studio STL seq_cst ld/st are
implemented using normal load/stores and explicit fences:
	`dmb ish + str + dmb ish`
	`ldr + dmb ish`

This patch uses fences for MSVC target whenever we write to the
memory in a sequentially consistent way so that we don't rely on
the assumptions that just using LDAR/STLR will give us sequentially
consistent ordering.


https://reviews.llvm.org/D141748

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/atomic-ops-msvc.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141748.489190.patch
Type: text/x-patch
Size: 11436 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230114/8ed2697e/attachment.bin>


More information about the llvm-commits mailing list