1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -amdgpu-promote-alloca < %s | FileCheck %s 2 3; Make sure this allocates the correct size if the alloca has a non-0 4; number of elements. 5 6; CHECK-LABEL: @array_alloca( 7; CHECK: %stack = alloca i32, i32 5, align 4 8define amdgpu_kernel void @array_alloca(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) #0 { 9entry: 10 %stack = alloca i32, i32 5, align 4 11 %ld0 = load i32, i32 addrspace(1)* %in, align 4 12 %arrayidx1 = getelementptr inbounds i32, i32* %stack, i32 %ld0 13 store i32 4, i32* %arrayidx1, align 4 14 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1 15 %ld1 = load i32, i32 addrspace(1)* %arrayidx2, align 4 16 %arrayidx3 = getelementptr inbounds i32, i32* %stack, i32 %ld1 17 store i32 5, i32* %arrayidx3, align 4 18 %arrayidx10 = getelementptr inbounds i32, i32* %stack, i32 0 19 %ld2 = load i32, i32* %arrayidx10, align 4 20 store i32 %ld2, i32 addrspace(1)* %out, align 4 21 %arrayidx12 = getelementptr inbounds i32, i32* %stack, i32 1 22 %ld3 = load i32, i32* %arrayidx12 23 %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1 24 store i32 %ld3, i32 addrspace(1)* %arrayidx13 25 ret void 26} 27 28; CHECK-LABEL: @array_alloca_dynamic( 29; CHECK: %stack = alloca i32, i32 %size, align 4 30define amdgpu_kernel void @array_alloca_dynamic(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in, i32 %size) #0 { 31entry: 32 %stack = alloca i32, i32 %size, align 4 33 %ld0 = load i32, i32 addrspace(1)* %in, align 4 34 %arrayidx1 = getelementptr inbounds i32, i32* %stack, i32 %ld0 35 store i32 4, i32* %arrayidx1, align 4 36 %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1 37 %ld1 = load i32, i32 addrspace(1)* %arrayidx2, align 4 38 %arrayidx3 = getelementptr inbounds i32, i32* %stack, i32 %ld1 39 store i32 5, i32* %arrayidx3, align 4 40 %arrayidx10 = getelementptr inbounds i32, i32* %stack, i32 0 41 %ld2 = load i32, i32* %arrayidx10, align 4 42 store i32 %ld2, i32 addrspace(1)* %out, align 4 43 %arrayidx12 = getelementptr inbounds i32, i32* %stack, i32 1 44 %ld3 = load i32, i32* %arrayidx12 45 %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1 46 store i32 %ld3, i32 addrspace(1)* %arrayidx13 47 ret void 48} 49 50attributes #0 = { nounwind } 51