xref: /aosp_15_r20/external/llvm/test/Transforms/GlobalOpt/externally-initialized-aggregate.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -S -globalopt | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; This global is externally_initialized, so if we split it into scalars we
4*9880d681SAndroid Build Coastguard Worker; should keep that flag set on all of the new globals. This will prevent the
5*9880d681SAndroid Build Coastguard Worker; store to @a[0] from being constant propagated to the load in @foo, but will not
6*9880d681SAndroid Build Coastguard Worker; prevent @a[1] from being removed since it is dead.
7*9880d681SAndroid Build Coastguard Worker; CHECK: @a.0 = internal unnamed_addr externally_initialized global i32 undef
8*9880d681SAndroid Build Coastguard Worker; CHECK-NOT @a.1
9*9880d681SAndroid Build Coastguard Worker@a = internal externally_initialized global [2 x i32] undef, align 4
10*9880d681SAndroid Build Coastguard Worker; This is the same, but a struct rather than an array.
11*9880d681SAndroid Build Coastguard Worker; CHECK: @b.0 = internal unnamed_addr externally_initialized global i32 undef
12*9880d681SAndroid Build Coastguard Worker; CHECK-NOT @b.1
13*9880d681SAndroid Build Coastguard Worker@b = internal externally_initialized global {i32, i32} undef, align 4
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Workerdefine i32 @foo() {
16*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define i32 @foo
17*9880d681SAndroid Build Coastguard Workerentry:
18*9880d681SAndroid Build Coastguard Worker; This load uses the split global, but cannot be constant-propagated away.
19*9880d681SAndroid Build Coastguard Worker; CHECK: %0 = load i32, i32* @a.0
20*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @a, i32 0, i32 0), align 4
21*9880d681SAndroid Build Coastguard Worker  ret i32 %0
22*9880d681SAndroid Build Coastguard Worker}
23*9880d681SAndroid Build Coastguard Worker
24*9880d681SAndroid Build Coastguard Workerdefine i32 @bar() {
25*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define i32 @bar
26*9880d681SAndroid Build Coastguard Workerentry:
27*9880d681SAndroid Build Coastguard Worker; This load uses the split global, but cannot be constant-propagated away.
28*9880d681SAndroid Build Coastguard Worker; CHECK: %0 = load i32, i32* @b.0
29*9880d681SAndroid Build Coastguard Worker  %0 = load i32, i32* getelementptr inbounds ({i32, i32}, {i32, i32}* @b, i32 0, i32 0), align 4
30*9880d681SAndroid Build Coastguard Worker  ret i32 %0
31*9880d681SAndroid Build Coastguard Worker}
32*9880d681SAndroid Build Coastguard Worker
33*9880d681SAndroid Build Coastguard Workerdefine void @init() {
34*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: define void @init
35*9880d681SAndroid Build Coastguard Workerentry:
36*9880d681SAndroid Build Coastguard Worker; This store uses the split global, but cannot be constant-propagated away.
37*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 1, i32* @a.0
38*9880d681SAndroid Build Coastguard Worker  store i32 1, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @a, i32 0, i32 0), align 4
39*9880d681SAndroid Build Coastguard Worker; This store can be removed, because the second element of @a is never read.
40*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: store i32 2, i32* @a.1
41*9880d681SAndroid Build Coastguard Worker  store i32 2, i32* getelementptr inbounds ([2 x i32], [2 x i32]* @a, i32 0, i32 1), align 4
42*9880d681SAndroid Build Coastguard Worker
43*9880d681SAndroid Build Coastguard Worker; This store uses the split global, but cannot be constant-propagated away.
44*9880d681SAndroid Build Coastguard Worker; CHECK: store i32 3, i32* @b.0
45*9880d681SAndroid Build Coastguard Worker  store i32 3, i32* getelementptr inbounds ({i32, i32}, {i32, i32}* @b, i32 0, i32 0), align 4
46*9880d681SAndroid Build Coastguard Worker; This store can be removed, because the second element of @b is never read.
47*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: store i32 4, i32* @b.1
48*9880d681SAndroid Build Coastguard Worker  store i32 4, i32* getelementptr inbounds ({i32, i32}, {i32, i32}* @b, i32 0, i32 1), align 4
49*9880d681SAndroid Build Coastguard Worker  ret void
50*9880d681SAndroid Build Coastguard Worker}
51