| 1 |
; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=hawaii -passes=loop-unroll -unroll-threshold=57 -unroll-peel-count=0 -unroll-allow-partial=false -unroll-max-iteration-count-to-analyze=16 < %s | FileCheck %s |
| 2 |
|
| 3 |
@indices = external global [16 x i32] |
| 4 |
|
| 5 |
; CHECK-LABEL: @test_func_addrspacecast_cost_noop( |
| 6 |
; CHECK-NOT: br i1 |
| 7 |
define amdgpu_kernel void @test_func_addrspacecast_cost_noop(ptr addrspace(1) noalias nocapture %out, ptr addrspace(1) noalias nocapture %in) #0 { |
| 8 |
entry: |
| 9 |
br label %for.body |
| 10 |
|
| 11 |
for.body: |
| 12 |
%indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %entry ] |
| 13 |
%sum.02 = phi float [ %fmul, %for.body ], [ 0.0, %entry ] |
| 14 |
%idx.ptr = getelementptr inbounds [16 x i32], ptr @indices, i32 0, i32 %indvars.iv |
| 15 |
%index = load i32, ptr %idx.ptr |
| 16 |
%arrayidx.in = getelementptr inbounds float, ptr addrspace(1) %in, i32 %index |
| 17 |
%arrayidx.out = getelementptr inbounds float, ptr addrspace(1) %out, i32 %index |
| 18 |
%cast.in = addrspacecast ptr addrspace(1) %arrayidx.in to ptr |
| 19 |
%cast.out = addrspacecast ptr addrspace(1) %arrayidx.out to ptr |
| 20 |
%load = load float, ptr %cast.in |
| 21 |
%fmul = fmul float %load, %sum.02 |
| 22 |
store float %fmul, ptr %cast.out |
| 23 |
%indvars.iv.next = add i32 %indvars.iv, 1 |
| 24 |
%exitcond = icmp eq i32 %indvars.iv.next, 16 |
| 25 |
br i1 %exitcond, label %for.end, label %for.body |
| 26 |
|
| 27 |
for.end: |
| 28 |
ret void |
| 29 |
} |
| 30 |
|
| 31 |
; Free, but not a no-op |
| 32 |
; CHECK-LABEL: @test_func_addrspacecast_cost_free( |
| 33 |
; CHECK-NOT: br i1 |
| 34 |
define amdgpu_kernel void @test_func_addrspacecast_cost_free(ptr noalias nocapture %out, ptr noalias nocapture %in) #0 { |
| 35 |
entry: |
| 36 |
br label %for.body |
| 37 |
|
| 38 |
for.body: |
| 39 |
%indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %entry ] |
| 40 |
%sum.02 = phi float [ %fmul, %for.body ], [ 0.0, %entry ] |
| 41 |
%idx.ptr = getelementptr inbounds [16 x i32], ptr @indices, i32 0, i32 %indvars.iv |
| 42 |
%index = load i32, ptr %idx.ptr |
| 43 |
%arrayidx.in = getelementptr inbounds float, ptr %in, i32 %index |
| 44 |
%arrayidx.out = getelementptr inbounds float, ptr %out, i32 %index |
| 45 |
%cast.in = addrspacecast ptr %arrayidx.in to ptr addrspace(3) |
| 46 |
%cast.out = addrspacecast ptr %arrayidx.out to ptr addrspace(3) |
| 47 |
%load = load float, ptr addrspace(3) %cast.in |
| 48 |
%fmul = fmul float %load, %sum.02 |
| 49 |
store float %fmul, ptr addrspace(3) %cast.out |
| 50 |
%indvars.iv.next = add i32 %indvars.iv, 1 |
| 51 |
%exitcond = icmp eq i32 %indvars.iv.next, 16 |
| 52 |
br i1 %exitcond, label %for.end, label %for.body |
| 53 |
|
| 54 |
for.end: |
| 55 |
ret void |
| 56 |
} |
| 57 |
|
| 58 |
; CHECK-LABEL: @test_func_addrspacecast_cost_nonfree( |
| 59 |
; CHECK: br i1 %exitcond |
| 60 |
define amdgpu_kernel void @test_func_addrspacecast_cost_nonfree(ptr addrspace(3) noalias nocapture %out, ptr addrspace(3) noalias nocapture %in) #0 { |
| 61 |
entry: |
| 62 |
br label %for.body |
| 63 |
|
| 64 |
for.body: |
| 65 |
%indvars.iv = phi i32 [ %indvars.iv.next, %for.body ], [ 0, %entry ] |
| 66 |
%sum.02 = phi float [ %fmul, %for.body ], [ 0.0, %entry ] |
| 67 |
%idx.ptr = getelementptr inbounds [16 x i32], ptr @indices, i32 0, i32 %indvars.iv |
| 68 |
%index = load i32, ptr %idx.ptr |
| 69 |
%arrayidx.in = getelementptr inbounds float, ptr addrspace(3) %in, i32 %index |
| 70 |
%arrayidx.out = getelementptr inbounds float, ptr addrspace(3) %out, i32 %index |
| 71 |
%cast.in = addrspacecast ptr addrspace(3) %arrayidx.in to ptr |
| 72 |
%cast.out = addrspacecast ptr addrspace(3) %arrayidx.out to ptr |
| 73 |
%load = load float, ptr %cast.in |
| 74 |
%fmul = fmul float %load, %sum.02 |
| 75 |
store float %fmul, ptr %cast.out |
| 76 |
%indvars.iv.next = add i32 %indvars.iv, 1 |
| 77 |
%exitcond = icmp eq i32 %indvars.iv.next, 16 |
| 78 |
br i1 %exitcond, label %for.end, label %for.body |
| 79 |
|
| 80 |
for.end: |
| 81 |
ret void |
| 82 |
} |
| 83 |
|
| 84 |
attributes #0 = { nounwind } |
| 85 |
attributes #1 = { nounwind readnone speculatable } |