1 ; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=hawaii -loop-unroll -unroll-threshold=75 -unroll-peel-count=0 -unroll-allow-partial=false -unroll-max-iteration-count-to-analyze=16 < %s | FileCheck %s
3 ; CHECK-LABEL: @test_func_addrspacecast_cost_noop(
5 define amdgpu_kernel void @test_func_addrspacecast_cost_noop(float addrspace(1)* noalias nocapture %out, float addrspace(1)* noalias nocapture %in) #0 {
10 %indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
11 %sum.02 = phi float [ %fmul, %for.body ], [ 0.0, %entry ]
12 %arrayidx.in = getelementptr inbounds float, float addrspace(1)* %in, i32 %indvars.iv
13 %arrayidx.out = getelementptr inbounds float, float addrspace(1)* %out, i32 %indvars.iv
14 %cast.in = addrspacecast float addrspace(1)* %arrayidx.in to float*
15 %cast.out = addrspacecast float addrspace(1)* %arrayidx.out to float*
16 %load = load float, float* %cast.in
17 %fmul = fmul float %load, %sum.02
18 store float %fmul, float* %cast.out
19 %indvars.iv.next = add i32 %indvars.iv, 1
20 %exitcond = icmp eq i32 %indvars.iv.next, 16
21 br i1 %exitcond, label %for.end, label %for.body
27 ; Free, but not a no-op
28 ; CHECK-LABEL: @test_func_addrspacecast_cost_free(
30 define amdgpu_kernel void @test_func_addrspacecast_cost_free(float* noalias nocapture %out, float* noalias nocapture %in) #0 {
35 %indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
36 %sum.02 = phi float [ %fmul, %for.body ], [ 0.0, %entry ]
37 %arrayidx.in = getelementptr inbounds float, float* %in, i32 %indvars.iv
38 %arrayidx.out = getelementptr inbounds float, float* %out, i32 %indvars.iv
39 %cast.in = addrspacecast float* %arrayidx.in to float addrspace(3)*
40 %cast.out = addrspacecast float* %arrayidx.out to float addrspace(3)*
41 %load = load float, float addrspace(3)* %cast.in
42 %fmul = fmul float %load, %sum.02
43 store float %fmul, float addrspace(3)* %cast.out
44 %indvars.iv.next = add i32 %indvars.iv, 1
45 %exitcond = icmp eq i32 %indvars.iv.next, 16
46 br i1 %exitcond, label %for.end, label %for.body
52 ; CHECK-LABEL: @test_func_addrspacecast_cost_nonfree(
53 ; CHECK: br i1 %exitcond
54 define amdgpu_kernel void @test_func_addrspacecast_cost_nonfree(float addrspace(3)* noalias nocapture %out, float addrspace(3)* noalias nocapture %in) #0 {
59 %indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
60 %sum.02 = phi float [ %fmul, %for.body ], [ 0.0, %entry ]
61 %arrayidx.in = getelementptr inbounds float, float addrspace(3)* %in, i32 %indvars.iv
62 %arrayidx.out = getelementptr inbounds float, float addrspace(3)* %out, i32 %indvars.iv
63 %cast.in = addrspacecast float addrspace(3)* %arrayidx.in to float*
64 %cast.out = addrspacecast float addrspace(3)* %arrayidx.out to float*
65 %load = load float, float* %cast.in
66 %fmul = fmul float %load, %sum.02
67 store float %fmul, float* %cast.out
68 %indvars.iv.next = add i32 %indvars.iv, 1
69 %exitcond = icmp eq i32 %indvars.iv.next, 16
70 br i1 %exitcond, label %for.end, label %for.body
76 attributes #0 = { nounwind }
77 attributes #1 = { nounwind readnone speculatable }