ARM: sink atomic release barrier as far as possible into cmpxchg.
authorTim Northover <tnorthover@apple.com>
Mon, 22 Feb 2016 20:55:50 +0000 (20:55 +0000)
committerTim Northover <tnorthover@apple.com>
Mon, 22 Feb 2016 20:55:50 +0000 (20:55 +0000)
commitd32f8e60bf819e75f496f060b3f01bb8dc68fc42
tree94164c061e87f19f50cd2ae09a0309eb5575a558
parentc5b668deb8848bca64e71efab5a3477857548e0f
ARM: sink atomic release barrier as far as possible into cmpxchg.

DMB instructions can be expensive, so it's best to avoid them if possible. In
atomicrmw operations there will always be an attempted store so a release
barrier is always needed, but in the cmpxchg case we can delay the DMB until we
know we'll definitely try to perform a store (and so need release semantics).

In the strong cmpxchg case this isn't quite free: we must duplicate the LDREX
instructions to skip the barrier on subsequent iterations. The basic outline
becomes:

        ldrex rOld, [rAddr]
        cmp rOld, rDesired
        bne Ldone
        dmb
    Lloop:
        strex rRes, rNew, [rAddr]
        cbz rRes Ldone
        ldrex rOld, [rAddr]
        cmp rOld, rDesired
        beq Lloop
    Ldone:

So we'll skip this version for strong operations in "minsize" functions.

llvm-svn: 261568
llvm/lib/CodeGen/AtomicExpandPass.cpp
llvm/test/CodeGen/ARM/atomic-64bit.ll
llvm/test/CodeGen/ARM/atomic-op.ll
llvm/test/CodeGen/ARM/cmpxchg-idioms.ll
llvm/test/CodeGen/ARM/cmpxchg-weak.ll
llvm/test/Transforms/AtomicExpand/ARM/atomic-expansion-v7.ll
llvm/test/Transforms/AtomicExpand/ARM/cmpxchg-weak.ll