[llvm] [LoopRotate][coroutines] Avoid hoisting addresses of thread-local variables outside loops in coroutines (PR #81937)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 16 14:22:06 PST 2024


================
@@ -612,7 +612,15 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
       // memory (without proving that the loop doesn't write).
       if (L->hasLoopInvariantOperands(Inst) && !Inst->mayReadFromMemory() &&
           !Inst->mayWriteToMemory() && !Inst->isTerminator() &&
-          !isa<DbgInfoIntrinsic>(Inst) && !isa<AllocaInst>(Inst)) {
+          !isa<DbgInfoIntrinsic>(Inst) && !isa<AllocaInst>(Inst) &&
+          // FIXME: It is not safe to cache the value of these instructions in
+          // coroutines, as the addresses of otherwise eligible variables (e.g.
+          // thread-local variables and errno) may change if the coroutine is
+          // resumed in a different thread. Therefore, we disable this
+          // optimization for correctness. However, this may block other correct
+          // optimizations. This should be reverted once we have a better model
+          // for memory access in coroutines.
+          !Inst->getFunction()->isPresplitCoroutine()) {
----------------
aeubanks wrote:

actually that requires MSSA and it's kinda a pain to make it optional so this is fine

https://github.com/llvm/llvm-project/pull/81937


More information about the llvm-commits mailing list