1 ; RUN: opt -S -globalopt < %s | FileCheck %s
3 ; This test is hint, what could globalOpt optimize and what it can't
4 ; FIXME: @tmp and @tmp2 can be safely set to 42
5 ; CHECK: @tmp = local_unnamed_addr global i32 0
6 ; CHECK: @tmp2 = local_unnamed_addr global i32 0
7 ; CHECK: @tmp3 = global i32 0
12 @ptrToTmp3 = global i32* null
14 @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
16 define i32 @TheAnswerToLifeTheUniverseAndEverything() {
20 define void @_GLOBAL__I_a() {
22 call void @_optimizable()
23 call void @_not_optimizable()
27 define void @_optimizable() {
31 %val = call i32 @TheAnswerToLifeTheUniverseAndEverything()
32 store i32 %val, i32* @tmp
33 store i32 %val, i32* %valptr
35 %0 = bitcast i32* %valptr to i8*
36 %barr = call i8* @llvm.launder.invariant.group(i8* %0)
37 %1 = bitcast i8* %barr to i32*
39 %val2 = load i32, i32* %1
40 store i32 %val2, i32* @tmp2
44 ; We can't step through launder.invariant.group here, because that would change
45 ; this load in @usage_of_globals()
46 ; val = load i32, i32* %ptrVal, !invariant.group !0
48 ; %val = load i32, i32* @tmp3, !invariant.group !0
49 ; and then we could assume that %val and %val2 to be the same, which coud be
50 ; false, because @changeTmp3ValAndCallBarrierInside() may change the value
52 define void @_not_optimizable() {
54 store i32 13, i32* @tmp3, !invariant.group !0
56 %0 = bitcast i32* @tmp3 to i8*
57 %barr = call i8* @llvm.launder.invariant.group(i8* %0)
58 %1 = bitcast i8* %barr to i32*
60 store i32* %1, i32** @ptrToTmp3
61 store i32 42, i32* %1, !invariant.group !0
65 define void @usage_of_globals() {
67 %ptrVal = load i32*, i32** @ptrToTmp3
68 %val = load i32, i32* %ptrVal, !invariant.group !0
70 call void @changeTmp3ValAndCallBarrierInside()
71 %val2 = load i32, i32* @tmp3, !invariant.group !0
75 declare void @changeTmp3ValAndCallBarrierInside()
77 declare i8* @llvm.launder.invariant.group(i8*)