[PATCH] D153932: [AliasAnalysis] Mark fences as not Mod'ing unescaped local values
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 12:39:55 PDT 2023
efriedma added a comment.
The relevant scenario would be a bit more complicated, I think, since we're returning that the fence is "ModRefInfo::Ref". Basically, that means non-atomic loads can move across the fence, but stores and atomic ops can't move across the fence. But consider transforming something like the following:
atomic<int*> y(nullptr);
// Thread 1:
x = 17;
z = x;
atomic_thread_fence(memory_order::release); // Address of x not yet taken.
y.store(&x, memory_order::relaxed);
assert(z == 17);
// Thread 2:
int* tmp = y.load(memory_order::acquire);
if (tmp != nullptr) *tmp += 100;
To something like:
atomic<int*> y(nullptr);
// Thread 1:
x = 17;
atomic_thread_fence(memory_order::release); // Address of x not yet taken.
z = x;
y.store(&x, memory_order::relaxed);
assert(z == 17);
// Thread 2:
int* tmp = y.load(memory_order::acquire);
if (tmp != nullptr) *tmp += 100;
The original is legal C++, but the modified version has undefined behavior, I think.
And actually, I guess this reasoning also applies to hoisting/sinking across arbitrary calls, since any function can contain a fence. So BasicAAResult::getModRefInfo for CallInst also needs to be fixed.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D153932/new/
https://reviews.llvm.org/D153932
More information about the llvm-commits
mailing list