tls.ll 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ; RUN: opt < %s -globalopt -S | FileCheck %s
  2. declare void @wait()
  3. declare void @signal()
  4. declare void @start_thread(void ()*)
  5. @x = internal thread_local global [100 x i32] zeroinitializer, align 16
  6. @ip = internal global i32* null, align 8
  7. ; PR14309: GlobalOpt would think that the value of @ip is always the address of
  8. ; x[1]. However, that address is different for different threads so @ip cannot
  9. ; be replaced with a constant.
  10. define i32 @f() {
  11. entry:
  12. ; Set @ip to point to x[1] for thread 1.
  13. store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), i32** @ip, align 8
  14. ; Run g on a new thread.
  15. tail call void @start_thread(void ()* @g) nounwind
  16. tail call void @wait() nounwind
  17. ; Reset x[1] for thread 1.
  18. store i32 0, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), align 4
  19. ; Read the value of @ip, which now points at x[1] for thread 2.
  20. %0 = load i32*, i32** @ip, align 8
  21. %1 = load i32, i32* %0, align 4
  22. ret i32 %1
  23. ; CHECK-LABEL: @f(
  24. ; Make sure that the load from @ip hasn't been removed.
  25. ; CHECK: load i32*, i32** @ip
  26. ; CHECK: ret
  27. }
  28. define internal void @g() nounwind uwtable {
  29. entry:
  30. ; Set @ip to point to x[1] for thread 2.
  31. store i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), i32** @ip, align 8
  32. ; Store 50 in x[1] for thread 2.
  33. store i32 50, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @x, i64 0, i64 1), align 4
  34. tail call void @signal() nounwind
  35. ret void
  36. ; CHECK-LABEL: @g(
  37. ; Make sure that the store to @ip hasn't been removed.
  38. ; CHECK: store {{.*}} @ip
  39. ; CHECK: ret
  40. }