[PATCH] D88799: [MemCpyOpt] Check for throwing calls during call slot optimization
Eli Friedman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 15:28:50 PDT 2020
efriedma added inline comments.
================
Comment at: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp:835
+ }
+ }
+
----------------
nikic wrote:
> Replying to @efriedma's comment on https://reviews.llvm.org/D88805#inline-824472: I believe checking for throwing instructions rather than guaranteed-to-transfer is correct here, because cpyDest cannot be read between the call and the copy, as a precondition for the call-slot optimization. So even if one of the instructions does not return, an early write to cpyDest will not be observable, with two caveats:
> * The call itself might read cpyDest. We explicitly protect against this below (see the getModRefInfo and callCapturesBefore checks).
> * We might throw and the catching code might read cpyDest. That's what we protect against here.
The case I'm concerned about is a multithreaded context. Say there's an infinite loop between the call and the write to cpyDest. Then the current thread never touches cpyDest at all, so some other thread could legally use the memory.
If we're sure no other thread can access the memory, ensuring we don't throw/longjmp would be sufficient, for the reasons you describe.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88799/new/
https://reviews.llvm.org/D88799
More information about the llvm-commits
mailing list