[PATCH] D46597: [sanitizer] Correct 64-bit atomic_store on 32-bit "other" platforms
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 8 13:01:20 PDT 2018
cryptoad created this revision.
cryptoad added reviewers: dvyukov, alekseyshl.
Herald added subscribers: Sanitizers, delcypher, kubamracek.
I think there might be something to optimize in `atomic_store`.
Currently, if everything goes well (and we have a different new value), we
always iterate 3 times.
For example, `with a = 0`, `oldval = a`, `newval = 42`, we get:
oldval = 0, newval = 42, curval = 0
oldval = 0, newval = 42, curval = 42
oldval = 42, newval = 42, curval = 42
and then it breaks.
Unless I am not seeing something, I don't see a point to the third iteration.
If the current value is the one we want, we should just break.
This means that 2 iterations (with a different newval) should be sufficient to
achieve what we want.
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D46597
Files:
lib/sanitizer_common/sanitizer_atomic_clang_other.h
Index: lib/sanitizer_common/sanitizer_atomic_clang_other.h
===================================================================
--- lib/sanitizer_common/sanitizer_atomic_clang_other.h
+++ lib/sanitizer_common/sanitizer_atomic_clang_other.h
@@ -86,7 +86,7 @@
typename T::Type cur;
for (;;) {
cur = __sync_val_compare_and_swap(&a->val_dont_use, cmp, v);
- if (cmp == v)
+ if (cur == v)
break;
cmp = cur;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46597.145763.patch
Type: text/x-patch
Size: 451 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180508/29e51f10/attachment.bin>
More information about the llvm-commits
mailing list