xref: /aosp_15_r20/external/llvm/test/Transforms/GlobalOpt/GSROA-section.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; This test lets globalopt split the global struct and array into different
2*9880d681SAndroid Build Coastguard Worker; values. The pass needs to preserve section attribute.
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -globalopt -S | FileCheck %s
5*9880d681SAndroid Build Coastguard Worker; Check that the new global values still have their section assignment.
6*9880d681SAndroid Build Coastguard Worker; CHECK: @struct
7*9880d681SAndroid Build Coastguard Worker; CHECK: section ".foo"
8*9880d681SAndroid Build Coastguard Worker; CHECK: @array
9*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: section ".foo"
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker@struct = internal global { i32, i32 } zeroinitializer, section ".foo"
12*9880d681SAndroid Build Coastguard Worker@array = internal global [ 2 x i32 ] zeroinitializer
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Workerdefine i32 @foo() {
15*9880d681SAndroid Build Coastguard Worker  %A = load i32, i32* getelementptr ({ i32, i32 }, { i32, i32 }* @struct, i32 0, i32 0)
16*9880d681SAndroid Build Coastguard Worker  %B = load i32, i32* getelementptr ([ 2 x i32 ], [ 2 x i32 ]* @array, i32 0, i32 0)
17*9880d681SAndroid Build Coastguard Worker  ; Use the loaded values, so they won't get removed completely
18*9880d681SAndroid Build Coastguard Worker  %R = add i32 %A, %B
19*9880d681SAndroid Build Coastguard Worker  ret i32 %R
20*9880d681SAndroid Build Coastguard Worker}
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker; We put stores in a different function, so that the global variables won't get
23*9880d681SAndroid Build Coastguard Worker; optimized away completely.
24*9880d681SAndroid Build Coastguard Workerdefine void @bar(i32 %R) {
25*9880d681SAndroid Build Coastguard Worker  store i32 %R, i32* getelementptr ([ 2 x i32 ], [ 2 x i32 ]* @array, i32 0, i32 0)
26*9880d681SAndroid Build Coastguard Worker  store i32 %R, i32* getelementptr ({ i32, i32 }, { i32, i32 }* @struct, i32 0, i32 0)
27*9880d681SAndroid Build Coastguard Worker  ret void
28*9880d681SAndroid Build Coastguard Worker}
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker
31