1 ; RUN: opt -mtriple=amdgcn-- -O1 -S < %s | FileCheck %s --check-prefixes=FUNC,LOOP
2 ; RUN: opt -mtriple=amdgcn-- -passes='default<O1>' -S < %s | FileCheck %s --check-prefixes=FUNC,LOOP
3 ; RUN: opt -mtriple=amdgcn-- -O1 -S -disable-promote-alloca-to-vector < %s | FileCheck %s --check-prefixes=FUNC,FULL-UNROLL
4 ; RUN: opt -mtriple=amdgcn-- -passes='default<O1>' -S -disable-promote-alloca-to-vector < %s | FileCheck %s --check-prefixes=FUNC,FULL-UNROLL
6 target datalayout = "A5"
8 ; This test contains a simple loop that initializes an array declared in
9 ; private memory. This loop would be fully unrolled if we could not SROA
10 ; the alloca. Check that we successfully eliminate it before the unroll,
11 ; so that we do not need to fully unroll it.
13 ; FUNC-LABEL: @private_memory
16 ; LOOP: br i1 %{{[^,]+}}, label %exit, label %loop.header
19 ; FULL-UNROLL-COUNT-256: store i32 {{[0-9]+}}, i32 addrspace(5)*
22 ; FUNC: store i32 %{{[^,]+}}, i32 addrspace(1)* %out
23 define amdgpu_kernel void @private_memory(i32 addrspace(1)* %out, i32 %n) {
25 %alloca = alloca [16 x i32], addrspace(5)
29 %counter = phi i32 [0, %entry], [%inc, %loop.inc]
33 %salt = xor i32 %counter, %n
34 %idx = and i32 %salt, 15
35 %ptr = getelementptr [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 %idx
36 store i32 %counter, i32 addrspace(5)* %ptr
40 %inc = add i32 %counter, 1
41 %cmp = icmp sge i32 %counter, 255
42 br i1 %cmp, label %exit, label %loop.header
45 %gep = getelementptr [16 x i32], [16 x i32] addrspace(5)* %alloca, i32 0, i32 %n
46 %load = load i32, i32 addrspace(5)* %gep
47 store i32 %load, i32 addrspace(1)* %out