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 5 6target datalayout = "A5" 7 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. 12 13; FUNC-LABEL: @private_memory 14; LOOP-NOT: alloca 15; LOOP: loop.header: 16; LOOP: br i1 %{{[^,]+}}, label %exit, label %loop.header 17 18; FULL-UNROLL: alloca 19; FULL-UNROLL-COUNT-256: store i32 {{[0-9]+}}, i32 addrspace(5)* 20; FULL-UNROLL-NOT: br 21 22; FUNC: store i32 %{{[^,]+}}, i32 addrspace(1)* %out 23define amdgpu_kernel void @private_memory(i32 addrspace(1)* %out, i32 %n) { 24entry: 25 %alloca = alloca [16 x i32], addrspace(5) 26 br label %loop.header 27 28loop.header: 29 %counter = phi i32 [0, %entry], [%inc, %loop.inc] 30 br label %loop.body 31 32loop.body: 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 37 br label %loop.inc 38 39loop.inc: 40 %inc = add i32 %counter, 1 41 %cmp = icmp sge i32 %counter, 255 42 br i1 %cmp, label %exit, label %loop.header 43 44exit: 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 48 ret void 49} 50