59 lines · plain
1; RUN: opt < %s -passes=globalopt -S | FileCheck %s2; RUN: opt -emulated-tls < %s -passes=globalopt -S | FileCheck %s3 4declare void @wait()5declare void @signal()6declare void @start_thread(ptr)7 8@x = internal thread_local global [100 x i32] zeroinitializer, align 169@ip = internal global ptr null, align 810 11; PR14309: GlobalOpt would think that the value of @ip is always the address of12; x[1]. However, that address is different for different threads so @ip cannot13; be replaced with a constant.14 15define i32 @f() {16entry:17 ; Set @ip to point to x[1] for thread 1.18 %p = call ptr @llvm.threadlocal.address(ptr @x)19 %addr = getelementptr inbounds [100 x i32], ptr %p, i64 0, i64 120 store ptr %addr, ptr @ip, align 821 22 ; Run g on a new thread.23 tail call void @start_thread(ptr @g) nounwind24 tail call void @wait() nounwind25 26 ; Reset x[1] for thread 1.27 store i32 0, ptr %addr, align 428 29 ; Read the value of @ip, which now points at x[1] for thread 2.30 %0 = load ptr, ptr @ip, align 831 32 %1 = load i32, ptr %0, align 433 ret i32 %134 35; CHECK-LABEL: @f(36; Make sure that the load from @ip hasn't been removed.37; CHECK: load ptr, ptr @ip38; CHECK: ret39}40 41define internal void @g() nounwind uwtable {42entry:43 ; Set @ip to point to x[1] for thread 2.44 %p = call ptr @llvm.threadlocal.address(ptr @x)45 %addr = getelementptr inbounds [100 x i32], ptr %p, i64 0, i64 146 store ptr %addr, ptr @ip, align 847 48 ; Store 50 in x[1] for thread 2.49 store i32 50, ptr %addr, align 450 51 tail call void @signal() nounwind52 ret void53 54; CHECK-LABEL: @g(55; Make sure that the store to @ip hasn't been removed.56; CHECK: store {{.*}} @ip57; CHECK: ret58}59