xref: /aosp_15_r20/external/llvm/test/CodeGen/AMDGPU/gv-offset-folding.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -mtriple=amdgcn--amdhsa -mcpu=fiji -relocation-model=static < %s | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker@lds = external addrspace(3) global [4 x i32]
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Worker; Offset folding is an optimization done for global variables with relocations,
8*9880d681SAndroid Build Coastguard Worker; which allows you to store the offset in the r_addend of the relocation entry.
9*9880d681SAndroid Build Coastguard Worker; The offset is apllied to the variables address at link time, which eliminates
10*9880d681SAndroid Build Coastguard Worker; the need to emit shader instructions to do this calculation.
11*9880d681SAndroid Build Coastguard Worker; We don't use relocations for local memory, so we should never fold offsets
12*9880d681SAndroid Build Coastguard Worker; for local memory globals.
13*9880d681SAndroid Build Coastguard Worker
14*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: lds_no_offset:
15*9880d681SAndroid Build Coastguard Worker; CHECK ds_write_b32 v{{[0-9]+}}, v{{[0-9]+}} offset:4
16*9880d681SAndroid Build Coastguard Workerdefine void @lds_no_offset() {
17*9880d681SAndroid Build Coastguard Workerentry:
18*9880d681SAndroid Build Coastguard Worker  %ptr = getelementptr [4 x i32], [4 x i32] addrspace(3)* @lds, i32 0, i32 1
19*9880d681SAndroid Build Coastguard Worker  store i32 0, i32 addrspace(3)* %ptr
20*9880d681SAndroid Build Coastguard Worker  ret void
21*9880d681SAndroid Build Coastguard Worker}
22