1 ; RUN: opt -S -passes=globalopt < %s | FileCheck %s
3 ; CHECK: @llvm.global_ctors = appending global [1 x {{.*}}@_GLOBAL__I_c
4 @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_a, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_b, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_c, ptr null }]
6 ; CHECK: @tmp = local_unnamed_addr global i32 42
7 ; CHECK: @tmp2 = local_unnamed_addr global i32 42
8 ; CHECK: @tmp3 = global i32 42
12 @ptrToTmp3 = global ptr null
14 define i32 @TheAnswerToLifeTheUniverseAndEverything() {
18 define void @_GLOBAL__I_a() {
20 call void @_optimizable()
21 call void @_not_optimizable()
25 define void @_optimizable() {
29 %val = call i32 @TheAnswerToLifeTheUniverseAndEverything()
30 store i32 %val, ptr @tmp
31 store i32 %val, ptr %valptr
33 %barr = call ptr @llvm.launder.invariant.group(ptr %valptr)
35 %val2 = load i32, ptr %barr
36 store i32 %val2, ptr @tmp2
40 ; We can't step through launder.invariant.group here, because that would change
41 ; this load in @usage_of_globals()
42 ; %val = load i32, ptr %ptrVal, !invariant.group !0
44 ; %val = load i32, ptr @tmp3, !invariant.group !0
45 ; and then we could assume that %val and %val2 to be the same, which coud be
46 ; false, because @changeTmp3ValAndCallBarrierInside() may change the value
48 define void @_not_optimizable() {
50 store i32 13, ptr @tmp3, !invariant.group !0
52 %barr = call ptr @llvm.launder.invariant.group(ptr @tmp3)
54 store ptr %barr, ptr @ptrToTmp3
55 store i32 42, ptr %barr, !invariant.group !0
60 define void @usage_of_globals() {
62 %ptrVal = load ptr, ptr @ptrToTmp3
63 %val = load i32, ptr %ptrVal, !invariant.group !0
65 call void @changeTmp3ValAndCallBarrierInside()
66 %val2 = load i32, ptr @tmp3, !invariant.group !0
72 define void @_GLOBAL__I_b() {
74 %val = call i32 @TheAnswerToLifeTheUniverseAndEverything()
75 %p2 = call ptr @llvm.strip.invariant.group.p0(ptr @tmp4)
76 store i32 %val, ptr %p2
81 @tmp6 = global ptr null
82 ; CHECK: @tmp6 = local_unnamed_addr global ptr null
84 define ptr @_dont_return_param(ptr %p) {
85 %p2 = call ptr @llvm.launder.invariant.group(ptr %p)
89 ; We should bail out if we return any pointers derived via invariant.group intrinsics at any point.
90 define void @_GLOBAL__I_c() {
92 %tmp5 = call ptr @_dont_return_param(ptr @tmp5)
93 store ptr %tmp5, ptr @tmp6
98 declare void @changeTmp3ValAndCallBarrierInside()
100 declare ptr @llvm.launder.invariant.group(ptr)
101 declare ptr @llvm.strip.invariant.group.p0(ptr)