[PATCH] D120026: [ARM] Fix ARM backend to correctly use atomic expansion routines.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 17 02:04:57 PST 2022


efriedma created this revision.
efriedma added reviewers: dmgreen, SjoerdMeijer, t.p.northover, aemerson.
Herald added a subscriber: hiraditya.
efriedma requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Without this patch, clang would generate calls to __sync_* routines on targets where it does not make sense; we can't assume the routines exist on unknown targets.  Linux has special implementations of the routines that work on old ARM targets; other targets have no such routines.  In general, atomics operations which aren't natively supported should go through libatomic (__atomic_*) APIs, which can support arbitrary atomics through locks.

ARM targets older than v6, where this patch makes a difference, are rare in practice, but not completely extinct.  See, for example, discussion on D116088 <https://reviews.llvm.org/D116088>.

This also affects Cortex-M0, but I don't think __sync_* routines actually exist in any Cortex-M0 libraries. So in practice this just leads to a slightly different linker error for those cases, I think.

Mechanically, this patch does the following:

1. Ensures we run atomic expansion unconditionally; it never makes sense to completely skip it.
2. Fixes getMaxAtomicSizeInBitsSupported() so it returns an appropriate number on all ARM subtargets.
3. Fixes shouldExpandAtomicRMWInIR() and shouldExpandAtomicCmpXchgInIR() to correctly handle subtargets that don't have atomic instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120026

Files:
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/ARMSubtarget.cpp
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/test/CodeGen/ARM/atomic-64bit.ll
  llvm/test/CodeGen/ARM/atomic-load-store.ll
  llvm/test/CodeGen/ARM/atomic-op.ll
  llvm/test/CodeGen/ARM/atomic-ops-m33.ll
  llvm/test/CodeGen/ARM/atomicrmw_exclusive_monitor_ints.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120026.409547.patch
Type: text/x-patch
Size: 20450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220217/296b60ac/attachment.bin>


More information about the llvm-commits mailing list