This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix i128 cmpxchg using ldxp/stxp.
ClosedPublic

Authored by efriedma on Jul 14 2021, 11:25 PM.

Details

Summary

Basically two parts to this fix:

  1. Stop using AtomicExpand to expand cmpxchg i128
  2. Fix AArch64ExpandPseudoInsts to use a correct expansion. In particular, we can't exit the loop until an stxp succeeds; otherwise, the load can tear.

Fixes https://bugs.llvm.org/show_bug.cgi?id=51102

Diff Detail

Event Timeline

efriedma created this revision.Jul 14 2021, 11:25 PM
efriedma requested review of this revision.Jul 14 2021, 11:25 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2021, 11:25 PM
SjoerdMeijer added a subscriber: samparker.

This is something @samparker looked at recently, can you perhaps have a look this?

samparker accepted this revision.Jul 20 2021, 3:19 AM

This made my brain melt a little... anyway, from Section B 2.2.1 of Arm ARM:

When the Store-Exclusive of a Load-Exclusive/Store-Exclusive pair instruction
using two 64-bit quantities succeeds, it causes a single-copy atomic update
of the entire memory location being updated.

To atomically load two 64-bit quantities, perform a Load-Exclusive
pair/Store-Exclusive pair sequence of reading and writing the same value for
which the Store-Exclusive pair succeeds, and use the read values from the
Load-Exclusive pair.

And it looks like this is what we are doing.

Ordering changes also LGTM.

This revision is now accepted and ready to land.Jul 20 2021, 3:19 AM
This revision was landed with ongoing or failed builds.Jul 20 2021, 12:38 PM
This revision was automatically updated to reflect the committed changes.
MaskRay added inline comments.
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17058

This was unused. I deleted it in 2b79a4eeb101bc9662427353187e35b9bc9da116 to pacify -Wunused-but-set-variable

efriedma added inline comments.Jul 20 2021, 1:24 PM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17058

Fixed it to do what I meant to do in 664a1fd9f04de65f0a37d612845dc9e095abe067

@samparker Let me know if you want me to add more test coverage.

samparker added inline comments.Jul 21 2021, 12:22 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17058

Ah! Yes please, hard enough to get this stuff right so probably worth adding cases for the other orderings...

efriedma added inline comments.Jul 21 2021, 11:34 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17058
samparker added inline comments.Jul 22 2021, 12:32 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
17058

cheers!