1; RUN: opt -cost-model -analyze -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck  --check-prefixes=ALL,SPEED %s
2; RUN: opt -cost-model -cost-kind=code-size -analyze -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck --check-prefixes=ALL,SIZE %s
3; END.
4
5; ALL-LABEL: 'test_br_cost'
6; SPEED-NEXT: estimated cost of 7 for instruction: br i1
7; SPEED: estimated cost of 4 for instruction: br label
8; SPEED-NEXT: estimated cost of 1 for instruction: %phi = phi i32 [
9; SPEED-NEXT: estimated cost of 10 for instruction: ret void
10; SIZE-NEXT: estimated cost of 5 for instruction: br i1
11; SIZE: estimated cost of 1 for instruction: br label
12; SIZE-NEXT: estimated cost of 0 for instruction: %phi = phi i32 [
13; SIZE-NEXT: estimated cost of 1 for instruction: ret void
14define amdgpu_kernel void @test_br_cost(i32 addrspace(1)* %out, i32 addrspace(1)* %vaddr, i32 %b) #0 {
15bb0:
16  br i1 undef, label %bb1, label %bb2
17
18bb1:
19  %vec = load i32, i32 addrspace(1)* %vaddr
20  %add = add i32 %vec, %b
21  store i32 %add, i32 addrspace(1)* %out
22  br label %bb2
23
24bb2:
25  %phi = phi i32 [ %b, %bb0 ], [ %add, %bb1 ]
26  ret void
27}
28
29; ALL-LABEL: 'test_switch_cost'
30; SPEED-NEXT: estimated cost of 24 for instruction:   switch
31; SIZE-NEXT: estimated cost of 18 for instruction:   switch
32define amdgpu_kernel void @test_switch_cost(i32 %a) #0 {
33entry:
34  switch i32 %a, label %default [
35    i32 0, label %case0
36    i32 1, label %case1
37  ]
38
39case0:
40  store volatile i32 undef, i32 addrspace(1)* undef
41  ret void
42
43case1:
44  store volatile i32 undef, i32 addrspace(1)* undef
45  ret void
46
47default:
48  store volatile i32 undef, i32 addrspace(1)* undef
49  ret void
50
51end:
52  ret void
53}
54