[ARM] Prevent spilling between ldrex/strex pairs
authorTomas Matheson <tomas.matheson@arm.com>
Tue, 11 May 2021 16:15:07 +0000 (17:15 +0100)
committerTomas Matheson <tomas.matheson@arm.com>
Wed, 12 May 2021 08:43:21 +0000 (09:43 +0100)
commit34c098b780a27a90b5614ea3b949b9269835f2a5
tree269755224e60576e0f2c7e6447a622cb5f5cfb90
parentedf9d88266376a693b07668f733034d2f6b22072
[ARM] Prevent spilling between ldrex/strex pairs

Based on the same for AArch64: 4751cadcca45984d7671e594ce95aed8fe030bf1

At -O0, the fast register allocator may insert spills between the ldrex and
strex instructions inserted by AtomicExpandPass when expanding atomicrmw
instructions in LL/SC loops. To avoid this, expand to cmpxchg loops and
therefore expand the cmpxchg pseudos after register allocation.

Required a tweak to ARMExpandPseudo::ExpandCMP_SWAP to use the 4-byte encoding
of UXT, since the pseudo instruction can be allocated a high register (R8-R15)
which the 2-byte encoding doesn't support. However, the 4-byte encodings
are not present for ARM v8-M Baseline. To enable this, two new pseudos are
added for Thumb which are only valid for v8mbase, tCMP_SWAP_8 and
tCMP_SWAP_16.

The previously committed attempt in D101164 had to be reverted due to runtime
failures in the test suites. Rather than spending time fixing that
implementation (adding another implementation of atomic operations and more
divergence between backends) I have chosen to follow the approach taken in
D101163.

Differential Revision: https://reviews.llvm.org/D101898

Depends on D101912
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
llvm/lib/Target/ARM/ARMISelLowering.cpp
llvm/lib/Target/ARM/ARMInstrThumb.td
llvm/test/CodeGen/ARM/atomicrmw_exclusive_monitor_ints.ll