aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/Inline/AMDGPU/amdgpu-inline-alloca-argument-cost.ll
blob: 9bec92a25efa45ba924f2c69a798ebd6699fda81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
; RUN: opt -mtriple=amdgcn--amdhsa -S -passes=inline -inline-threshold=0 -debug-only=inline-cost %s 2>&1 | FileCheck %s

; REQUIRES: asserts

; Verify we are properly adding cost of the -amdgpu-inline-arg-alloca-cost to the threshold.

define void @local_access_only(ptr addrspace(5) %p, i32 %idx) {
  %arrayidx = getelementptr inbounds [64 x float], ptr addrspace(5) %p, i32 0, i32 %idx
  %value = load float, ptr addrspace(5) %arrayidx
  store float %value , ptr addrspace(5) %arrayidx, align 4
  ret void
}

; Below the cutoff, the alloca cost is 0, and only the cost of the instructions saved by sroa is counted
; CHECK: Analyzing call of local_access_only... (caller:test_inliner_sroa_single_below_cutoff)
; CHECK: NumAllocaArgs: 1
; CHECK: SROACostSavings: 10
; CHECK: SROACostSavingsLost: 0
; CHECK: Threshold: 66000
define amdgpu_kernel void @test_inliner_sroa_single_below_cutoff(ptr addrspace(1) %a, i32 %n) {
entry:
  %pvt_arr = alloca [64 x float], align 4, addrspace(5)
  call void @local_access_only(ptr addrspace(5) %pvt_arr, i32 4)
  ret void
}

; Above the cutoff, attribute a cost to the alloca
; CHECK: Analyzing call of local_access_only... (caller:test_inliner_sroa_single_above_cutoff)
; CHECK: NumAllocaArgs: 1
; CHECK: SROACostSavings: 66010
; CHECK: SROACostSavingsLost: 0
; CHECK: Threshold: 66000
define amdgpu_kernel void @test_inliner_sroa_single_above_cutoff(ptr addrspace(1) %a, i32 %n) {
entry:
  %pvt_arr = alloca [65 x float], align 4, addrspace(5)
  call void @local_access_only(ptr addrspace(5) %pvt_arr, i32 4)
  ret void
}

define void @use_first_externally(ptr addrspace(5) %p1, ptr addrspace(5) %p2) {
  call void @external(ptr addrspace(5) %p1)
  %arrayidx = getelementptr inbounds [64 x float], ptr addrspace(5) %p2, i32 0, i32 7
  %value = load float, ptr addrspace(5) %arrayidx
  store float %value , ptr addrspace(5) %arrayidx, align 4
  ret void
}

define void @use_both_externally(ptr addrspace(5) %p1, ptr addrspace(5) %p2) {
  call void @external(ptr addrspace(5) %p1)
  call void @external(ptr addrspace(5) %p2)
  ret void
}

; One array cannot get handled by SROA 
; CHECK: Analyzing call of use_first_externally... (caller:test_inliner_sroa_double)
; CHECK: NumAllocaArgs: 2
; CHECK: SROACostSavings: 32502
; CHECK: SROACostSavingsLost: 33507
; CHECK: Threshold: 66000
define amdgpu_kernel void @test_inliner_sroa_double() {
entry:
  %pvt_arr1 = alloca [33 x float], align 4, addrspace(5)
  %pvt_arr2 = alloca [32 x float], align 4, addrspace(5)
  call void @use_first_externally(ptr addrspace(5) %pvt_arr1, ptr addrspace(5) %pvt_arr2)
  ret void
}

; The two arrays cannot get handled by SROA 
; CHECK: Analyzing call of use_both_externally... (caller:test_inliner_no_sroa)
; CHECK: NumAllocaArgs: 2
; CHECK: SROACostSavings: 0
; CHECK: SROACostSavingsLost: 65999
; CHECK: Threshold: 66000
define amdgpu_kernel void @test_inliner_no_sroa() {
entry:
  %pvt_arr1 = alloca [33 x float], align 4, addrspace(5)
  %pvt_arr2 = alloca [32 x float], align 4, addrspace(5)
  call void @use_both_externally(ptr addrspace(5) %pvt_arr1, ptr addrspace(5) %pvt_arr2)
  ret void
}

; No private arrays
; CHECK: Analyzing call of use_both_externally... (caller:test_inliner_no_alloc)
; CHECK: NumAllocaArgs: 0
; CHECK: SROACostSavings: 0
; CHECK: SROACostSavingsLost: 0
; CHECK: Threshold: 0
define amdgpu_kernel void @test_inliner_no_alloc(ptr addrspace(5) %a, ptr addrspace(5) %b) {
entry:
  call void @use_both_externally(ptr addrspace(5) %a, ptr addrspace(5) %b)
  ret void
}

declare void @external(ptr addrspace(5) %p)