@@ -1217,6 +1217,14 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
12171217 if (CI->isConvergent ())
12181218 return false ;
12191219
1220+ // FIXME: Current LLVM IR semantics don't work well with coroutines and
1221+ // thread local globals. We currently treat getting the address of a thread
1222+ // local global as not accessing memory, even though it may not be a
1223+ // constant throughout a function with coroutines. Remove this check after
1224+ // we better model semantics of thread local globals.
1225+ if (CI->getFunction ()->isPresplitCoroutine ())
1226+ return false ;
1227+
12201228 using namespace PatternMatch ;
12211229 if (match (CI, m_Intrinsic<Intrinsic::assume>()))
12221230 // Assumes don't actually alias anything or throw
@@ -1225,14 +1233,6 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
12251233 // Handle simple cases by querying alias analysis.
12261234 MemoryEffects Behavior = AA->getMemoryEffects (CI);
12271235
1228- // FIXME: we don't handle the semantics of thread local well. So that the
1229- // address of thread locals are fake constants in coroutines. So We forbid
1230- // to treat onlyReadsMemory call in coroutines as constants now. Note that
1231- // it is possible to hide a thread local access in a onlyReadsMemory call.
1232- // Remove this check after we handle the semantics of thread locals well.
1233- if (Behavior.onlyReadsMemory () && CI->getFunction ()->isPresplitCoroutine ())
1234- return false ;
1235-
12361236 if (Behavior.doesNotAccessMemory ())
12371237 return true ;
12381238 if (Behavior.onlyReadsMemory ()) {
0 commit comments