xref: /aosp_15_r20/external/llvm/test/Transforms/GlobalOpt/2008-07-17-addrspace.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. This used to crash, because globalopt forgot to put the new var in the
3*9880d681SAndroid Build Coastguard Worker; same address space as the old one.
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; RUN: opt < %s -globalopt -S | FileCheck %s
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Worker; Check that the new global values still have their address space
8*9880d681SAndroid Build Coastguard Worker; CHECK: addrspace(1) global
9*9880d681SAndroid Build Coastguard Worker; CHECK: addrspace(1) global
10*9880d681SAndroid Build Coastguard Worker
11*9880d681SAndroid Build Coastguard Worker@struct = internal addrspace(1) global { i32, i32 } zeroinitializer
12*9880d681SAndroid Build Coastguard Worker@array = internal addrspace(1) 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 addrspace(1) * getelementptr ({ i32, i32 }, { i32, i32 } addrspace(1) * @struct, i32 0, i32 0)
16*9880d681SAndroid Build Coastguard Worker  %B = load i32, i32 addrspace(1) * getelementptr ([ 2 x i32 ], [ 2 x i32 ] addrspace(1) * @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 addrspace(1) * getelementptr ([ 2 x i32 ], [ 2 x i32 ] addrspace(1) * @array, i32 0, i32 0)
26*9880d681SAndroid Build Coastguard Worker  store i32 %R, i32 addrspace(1) * getelementptr ({ i32, i32 }, { i32, i32 } addrspace(1) * @struct, i32 0, i32 0)
27*9880d681SAndroid Build Coastguard Worker  ret void
28*9880d681SAndroid Build Coastguard Worker}
29