1 ; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=hawaii -passes=loop-unroll -unroll-threshold=49 -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(ptr addrspace(1) noalias nocapture %out, ptr 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, ptr addrspace(1) %in, i32 %indvars.iv
13 %arrayidx.out = getelementptr inbounds float, ptr addrspace(1) %out, i32 %indvars.iv
14 %cast.in = addrspacecast ptr addrspace(1) %arrayidx.in to ptr
15 %cast.out = addrspacecast ptr addrspace(1) %arrayidx.out to ptr
16 %load = load float, ptr %cast.in
17 %fmul = fmul float %load, %sum.02
18 store float %fmul, ptr %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(ptr noalias nocapture %out, ptr 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, ptr %in, i32 %indvars.iv
38 %arrayidx.out = getelementptr inbounds float, ptr %out, i32 %indvars.iv
39 %cast.in = addrspacecast ptr %arrayidx.in to ptr addrspace(3)
40 %cast.out = addrspacecast ptr %arrayidx.out to ptr addrspace(3)
41 %load = load float, ptr addrspace(3) %cast.in
42 %fmul = fmul float %load, %sum.02
43 store float %fmul, ptr 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(ptr addrspace(3) noalias nocapture %out, ptr 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, ptr addrspace(3) %in, i32 %indvars.iv
62 %arrayidx.out = getelementptr inbounds float, ptr addrspace(3) %out, i32 %indvars.iv
63 %cast.in = addrspacecast ptr addrspace(3) %arrayidx.in to ptr
64 %cast.out = addrspacecast ptr addrspace(3) %arrayidx.out to ptr
65 %load = load float, ptr %cast.in
66 %fmul = fmul float %load, %sum.02
67 store float %fmul, ptr %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 }