[llvm-bugs] [Bug 51102] New: [AArch64] Wrong code generated (?) for compare_exchange_strong on __int128_t
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jul 14 22:30:10 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51102
Bug ID: 51102
Summary: [AArch64] Wrong code generated (?) for
compare_exchange_strong on __int128_t
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: AArch64
Assignee: unassignedbugs at nondot.org
Reporter: efriedma at quicinc.com
CC: arnaud.degrandmaison at arm.com,
llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
Ties.Stuij at arm.com
Consider:
#include <stdatomic.h>
__int128_t ff(_Atomic __int128_t *p) {
__int128_t e = 0;
atomic_compare_exchange_strong(p, &e, 0);
return e;
}
ff:
mov x8, x0
.LBB0_1:
ldaxp x0, x1, [x8]
orr x9, x0, x1
cbnz x9, .LBB0_4
stlxp w9, xzr, xzr, [x8]
cbnz w9, .LBB0_1
ret
.LBB0_4:
clrex
ret
This sequence is subtly wrong in the case where the cmpxchg fails.
Specifically, the ldaxp is not single-copy atomic, so the returned value might
tear. At least, that's my understanding of the rules here. So we need to
replace the "clrex" with a sequence like "stlxp w9, x0, x1, [x8]; cbnz w9,
.LBB0_1".
Not sure if this sort of tearing can actually happen in practice on commonly
used AArch64 chips.
I'll throw together a patch.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210715/4ab65ba9/attachment.html>
More information about the llvm-bugs
mailing list