// Handle simple cases by querying alias analysis.
MemoryEffects Behavior = AA->getMemoryEffects(CI);
+
+ // FIXME: we don't handle the semantics of thread local well. So that the
+ // address of thread locals are fake constants in coroutines. So We forbid
+ // to treat onlyReadsMemory call in coroutines as constants now. Note that
+ // it is possible to hide a thread local access in a onlyReadsMemory call.
+ // Remove this check after we handle the semantics of thread locals well.
+ if (Behavior.onlyReadsMemory() && CI->getFunction()->isPresplitCoroutine())
+ return false;
+
if (Behavior.doesNotAccessMemory())
return true;
if (Behavior.onlyReadsMemory()) {
; CHECK-NEXT: [[P:%.*]] = alloca i64, align 8
; CHECK-NEXT: br label [[LOOP_PREHEADER:%.*]]
; CHECK: loop.preheader:
-; CHECK-NEXT: [[THREAD_LOCAL_0:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @tls)
-; CHECK-NEXT: [[THREAD_LOCAL_1:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @tls)
-; CHECK-NEXT: [[CMP_0:%.*]] = icmp eq ptr [[THREAD_LOCAL_0]], [[THREAD_LOCAL_1]]
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
; CHECK: for.body:
; CHECK-NEXT: [[I:%.*]] = phi i64 [ 0, [[LOOP_PREHEADER]] ], [ [[I_NEXT:%.*]], [[LOOP_END:%.*]] ]
; CHECK-NEXT: [[I_NEXT]] = add i64 [[I]], 1
+; CHECK-NEXT: [[THREAD_LOCAL_0:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @tls)
; CHECK-NEXT: [[READONLY_0:%.*]] = call ptr @readonly_funcs()
; CHECK-NEXT: [[SUSPEND:%.*]] = call i8 @llvm.coro.suspend(token none, i1 false)
; CHECK-NEXT: switch i8 [[SUSPEND]], label [[EXIT:%.*]] [
; CHECK-NEXT: i8 0, label [[AWAIT_READY:%.*]]
; CHECK-NEXT: ]
; CHECK: await.ready:
+; CHECK-NEXT: [[THREAD_LOCAL_1:%.*]] = call ptr @llvm.threadlocal.address.p0(ptr @tls)
; CHECK-NEXT: [[READONLY_1:%.*]] = call ptr @readonly_funcs()
+; CHECK-NEXT: [[CMP_0:%.*]] = icmp eq ptr [[THREAD_LOCAL_0]], [[THREAD_LOCAL_1]]
; CHECK-NEXT: [[CMP_1:%.*]] = icmp eq ptr [[READONLY_0]], [[READONLY_1]]
; CHECK-NEXT: [[CMP:%.*]] = and i1 [[CMP_0]], [[CMP_1]]
; CHECK-NEXT: br i1 [[CMP]], label [[NOT_REACHABLE:%.*]], label [[LOOP_END]]