brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.7 KiB · bd29e9e Raw
142 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals2; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-module-lds < %s | FileCheck %s3 4; Regression test for issue 1601815; One variable is chosen to be assigned at zero. Here, that's @both6; Then other variables should be allocated at fixed offsets from that provided7; they are allocated by all the other kernels that presently allocate the8; variable at address zero.9; The failure mode was in that second check - variables could be added to10; the module scope zero address struct even when some of the kernels allocating11; that struct do not need the additional variable.12 13; With current llvm, all three of these integers are put in the module scope struct, when14; neither kern_one or kern_two access all three.15 16@both = addrspace(3) global i32 poison17@both_second = addrspace(3) global i16 poison ; a second field in the module struct18@one = addrspace(3) global i32 poison19@two = addrspace(3) global i32 poison20 21 22;.23; CHECK: @llvm.amdgcn.module.lds = internal addrspace(3) global %llvm.amdgcn.module.lds.t poison, align 4, !absolute_symbol [[META0:![0-9]+]]24; CHECK: @llvm.compiler.used = appending addrspace(1) global [1 x ptr] [ptr addrspacecast (ptr addrspace(3) @llvm.amdgcn.module.lds to ptr)], section "llvm.metadata"25; CHECK: @llvm.amdgcn.kernel.kern_one.lds = internal addrspace(3) global %llvm.amdgcn.kernel.kern_one.lds.t poison, align 4, !absolute_symbol [[META1:![0-9]+]]26; CHECK: @llvm.amdgcn.kernel.kern_two.lds = internal addrspace(3) global %llvm.amdgcn.kernel.kern_two.lds.t poison, align 4, !absolute_symbol [[META1]]27; CHECK: @llvm.amdgcn.kernel.kern_block_direct_allocation.lds = internal addrspace(3) global %llvm.amdgcn.kernel.kern_block_direct_allocation.lds.t poison, align 4, !absolute_symbol [[META1]]28 29;.30define void @func_one() {31; CHECK-LABEL: define {{[^@]+}}@func_one() {32; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.amdgcn.lds.kernel.id()33; CHECK-NEXT:    [[VAL0:%.*]] = load i32, ptr addrspace(3) @llvm.amdgcn.module.lds, align 4, !noalias [[META2:![0-9]+]]34; CHECK-NEXT:    [[ONE:%.*]] = getelementptr inbounds [3 x [2 x i32]], ptr addrspace(4) @llvm.amdgcn.lds.offset.table, i32 0, i32 [[TMP1]], i32 035; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr addrspace(4) [[ONE]], align 436; CHECK-NEXT:    [[ONE1:%.*]] = inttoptr i32 [[TMP2]] to ptr addrspace(3)37; CHECK-NEXT:    store i32 [[VAL0]], ptr addrspace(3) [[ONE1]], align 438; CHECK-NEXT:    store i16 10, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T:%.*]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1), align 4, !noalias [[META11:![0-9]+]]39; CHECK-NEXT:    ret void40;41  %val0 = load i32, ptr addrspace(3) @both42  store i32 %val0, ptr addrspace(3) @one43  store i16 10, ptr addrspace(3) @both_second44  ret void45}46 47define amdgpu_kernel void @kern_one() {48; CHECK-LABEL: define {{[^@]+}}@kern_one49; CHECK-SAME: () #[[ATTR0:[0-9]+]] !llvm.amdgcn.lds.kernel.id [[META16:![0-9]+]] {50; CHECK-NEXT:  entry:51; CHECK-NEXT:    call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel.kern_one.lds) ]52; CHECK-NEXT:    call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ], !noalias [[META17:![0-9]+]]53; CHECK-NEXT:    call void @func_one()54; CHECK-NEXT:    ret void55;56entry:57  call void @func_one()58  ret void59}60 61define void @func_two() {62; CHECK-LABEL: define {{[^@]+}}@func_two() {63; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.amdgcn.lds.kernel.id()64; CHECK-NEXT:    [[VAL0:%.*]] = load i32, ptr addrspace(3) @llvm.amdgcn.module.lds, align 4, !noalias [[META2]]65; CHECK-NEXT:    [[TWO:%.*]] = getelementptr inbounds [3 x [2 x i32]], ptr addrspace(4) @llvm.amdgcn.lds.offset.table, i32 0, i32 [[TMP1]], i32 166; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr addrspace(4) [[TWO]], align 467; CHECK-NEXT:    [[TWO1:%.*]] = inttoptr i32 [[TMP2]] to ptr addrspace(3)68; CHECK-NEXT:    store i32 [[VAL0]], ptr addrspace(3) [[TWO1]], align 469; CHECK-NEXT:    store i16 20, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T:%.*]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1), align 4, !noalias [[META11]]70; CHECK-NEXT:    ret void71;72  %val0 = load i32, ptr addrspace(3) @both73  store i32 %val0, ptr addrspace(3) @two74  store i16 20, ptr addrspace(3) @both_second75  ret void76}77 78define amdgpu_kernel void @kern_two() {79; CHECK-LABEL: define {{[^@]+}}@kern_two80; CHECK-SAME: () #[[ATTR0]] !llvm.amdgcn.lds.kernel.id [[META18:![0-9]+]] {81; CHECK-NEXT:  entry:82; CHECK-NEXT:    call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel.kern_two.lds) ]83; CHECK-NEXT:    call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ], !alias.scope [[META19:![0-9]+]], !noalias [[META20:![0-9]+]]84; CHECK-NEXT:    call void @func_two()85; CHECK-NEXT:    ret void86;87entry:88  call void @func_two()89  ret void90}91 92; Unrelated to the bug at hand, but if a variable is only93; reachable from a single kernel, it gets allocated to a fixed94; address independent of the module scope struct. This kernel95; means the key variables miss that optimisation while @both96; remains the best candidate for address zero allocation.97define void @func_block_direct_allocation() {98; CHECK-LABEL: define {{[^@]+}}@func_block_direct_allocation() {99; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @llvm.amdgcn.lds.kernel.id()100; CHECK-NEXT:    [[ONE:%.*]] = getelementptr inbounds [3 x [2 x i32]], ptr addrspace(4) @llvm.amdgcn.lds.offset.table, i32 0, i32 [[TMP1]], i32 0101; CHECK-NEXT:    [[TMP2:%.*]] = load i32, ptr addrspace(4) [[ONE]], align 4102; CHECK-NEXT:    [[ONE1:%.*]] = inttoptr i32 [[TMP2]] to ptr addrspace(3)103; CHECK-NEXT:    [[VAL1:%.*]] = load i32, ptr addrspace(3) [[ONE1]], align 4104; CHECK-NEXT:    [[TWO:%.*]] = getelementptr inbounds [3 x [2 x i32]], ptr addrspace(4) @llvm.amdgcn.lds.offset.table, i32 0, i32 [[TMP1]], i32 1105; CHECK-NEXT:    [[TMP3:%.*]] = load i32, ptr addrspace(4) [[TWO]], align 4106; CHECK-NEXT:    [[TWO2:%.*]] = inttoptr i32 [[TMP3]] to ptr addrspace(3)107; CHECK-NEXT:    [[VAL2:%.*]] = load i32, ptr addrspace(3) [[TWO2]], align 4108; CHECK-NEXT:    [[SUM:%.*]] = add i32 [[VAL1]], [[VAL2]]109; CHECK-NEXT:    store i32 [[SUM]], ptr addrspace(3) @llvm.amdgcn.module.lds, align 4, !noalias [[META2]]110; CHECK-NEXT:    store i16 30, ptr addrspace(3) getelementptr inbounds ([[LLVM_AMDGCN_MODULE_LDS_T:%.*]], ptr addrspace(3) @llvm.amdgcn.module.lds, i32 0, i32 1), align 4, !noalias [[META11]]111; CHECK-NEXT:    ret void112;113  %val1 = load i32, ptr addrspace(3) @one114  %val2 = load i32, ptr addrspace(3) @two115  %sum = add i32 %val1, %val2116  store i32 %sum, ptr addrspace(3) @both117  store i16 30, ptr addrspace(3) @both_second118  ret void119}120 121define amdgpu_kernel void @kern_block_direct_allocation() {122; CHECK-LABEL: define {{[^@]+}}@kern_block_direct_allocation123; CHECK-SAME: () #[[ATTR1:[0-9]+]] !llvm.amdgcn.lds.kernel.id [[META21:![0-9]+]] {124; CHECK-NEXT:    call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.kernel.kern_block_direct_allocation.lds) ], !alias.scope [[META22:![0-9]+]], !noalias [[META25:![0-9]+]]125; CHECK-NEXT:    call void @llvm.donothing() [ "ExplicitUse"(ptr addrspace(3) @llvm.amdgcn.module.lds) ]126; CHECK-NEXT:    call void @func_block_direct_allocation()127; CHECK-NEXT:    call void @func_one()128; CHECK-NEXT:    call void @func_two()129; CHECK-NEXT:    ret void130;131  call void @func_block_direct_allocation()132  call void @func_one()133  call void @func_two()134  ret void135}136;.137; CHECK: attributes #[[ATTR0]] = { "amdgpu-lds-size"="12" }138; CHECK: attributes #[[ATTR1]] = { "amdgpu-lds-size"="16" }139; CHECK: attributes #[[ATTR2:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(none) }140; CHECK: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }141;.142