blob: ac35dd0bef5cdc110f2f89113455a7b125da8dd4 [file] [log] [blame]
Matt Arsenault711b3902015-08-07 20:18:34 +00001; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=bonaire < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-CI %s
Matt Arsenault7aad8fd2017-01-24 22:02:15 +00002; RUN: opt -S -codegenprepare -mtriple=amdgcn-unknown-unknown -mcpu=tonga -mattr=-flat-for-global < %s | FileCheck -check-prefix=OPT -check-prefix=OPT-VI %s
Matt Arsenault711b3902015-08-07 20:18:34 +00003; RUN: llc -march=amdgcn -mcpu=bonaire -mattr=-promote-alloca < %s | FileCheck -check-prefix=GCN -check-prefix=CI %s
Matt Arsenault7aad8fd2017-01-24 22:02:15 +00004; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -mattr=-promote-alloca < %s | FileCheck -check-prefix=GCN -check-prefix=VI %s
Matt Arsenault711b3902015-08-07 20:18:34 +00005
6; OPT-LABEL: @test_no_sink_flat_small_offset_i32(
7; OPT: getelementptr i32, i32 addrspace(4)* %in
8; OPT: br i1
9; OPT-NOT: ptrtoint
10
11; GCN-LABEL: {{^}}test_no_sink_flat_small_offset_i32:
12; GCN: flat_load_dword
13; GCN: {{^}}BB0_2:
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000014define amdgpu_kernel void @test_no_sink_flat_small_offset_i32(i32 addrspace(4)* %out, i32 addrspace(4)* %in, i32 %cond) {
Matt Arsenault711b3902015-08-07 20:18:34 +000015entry:
16 %out.gep = getelementptr i32, i32 addrspace(4)* %out, i64 999999
17 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 7
18 %tmp0 = icmp eq i32 %cond, 0
19 br i1 %tmp0, label %endif, label %if
20
21if:
22 %tmp1 = load i32, i32 addrspace(4)* %in.gep
23 br label %endif
24
25endif:
26 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
27 store i32 %x, i32 addrspace(4)* %out.gep
28 br label %done
29
30done:
31 ret void
32}
Matt Arsenaultf9bfeaf2015-12-01 23:04:00 +000033
34; OPT-LABEL: @test_sink_noop_addrspacecast_flat_to_global_i32(
35; OPT: getelementptr i32, i32 addrspace(4)* %out,
36; OPT-CI-NOT: getelementptr
37; OPT: br i1
38
39; OPT-CI: ptrtoint
40; OPT-CI: add
41; OPT-CI: inttoptr
42; OPT: br label
43
44; GCN-LABEL: {{^}}test_sink_noop_addrspacecast_flat_to_global_i32:
Nikolay Haustov4f672a32016-04-29 09:02:30 +000045; CI: buffer_load_dword {{v[0-9]+}}, off, s{{\[[0-9]+:[0-9]+\]}}, 0 offset:28
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000046define amdgpu_kernel void @test_sink_noop_addrspacecast_flat_to_global_i32(i32 addrspace(4)* %out, i32 addrspace(4)* %in, i32 %cond) {
Matt Arsenaultf9bfeaf2015-12-01 23:04:00 +000047entry:
48 %out.gep = getelementptr i32, i32 addrspace(4)* %out, i64 999999
49 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 7
50 %cast = addrspacecast i32 addrspace(4)* %in.gep to i32 addrspace(1)*
51 %tmp0 = icmp eq i32 %cond, 0
52 br i1 %tmp0, label %endif, label %if
53
54if:
55 %tmp1 = load i32, i32 addrspace(1)* %cast
56 br label %endif
57
58endif:
59 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
60 store i32 %x, i32 addrspace(4)* %out.gep
61 br label %done
62
63done:
64 ret void
65}
66
67; OPT-LABEL: @test_sink_noop_addrspacecast_flat_to_constant_i32(
68; OPT: getelementptr i32, i32 addrspace(4)* %out,
69; OPT-CI-NOT: getelementptr
70; OPT: br i1
71
72; OPT-CI: ptrtoint
73; OPT-CI: add
74; OPT-CI: inttoptr
75; OPT: br label
76
77; GCN-LABEL: {{^}}test_sink_noop_addrspacecast_flat_to_constant_i32:
78; CI: s_load_dword {{s[0-9]+}}, s{{\[[0-9]+:[0-9]+\]}}, 0xd
Matt Arsenault3dbeefa2017-03-21 21:39:51 +000079define amdgpu_kernel void @test_sink_noop_addrspacecast_flat_to_constant_i32(i32 addrspace(4)* %out, i32 addrspace(4)* %in, i32 %cond) {
Matt Arsenaultf9bfeaf2015-12-01 23:04:00 +000080entry:
81 %out.gep = getelementptr i32, i32 addrspace(4)* %out, i64 999999
82 %in.gep = getelementptr i32, i32 addrspace(4)* %in, i64 7
83 %cast = addrspacecast i32 addrspace(4)* %in.gep to i32 addrspace(2)*
84 %tmp0 = icmp eq i32 %cond, 0
85 br i1 %tmp0, label %endif, label %if
86
87if:
88 %tmp1 = load i32, i32 addrspace(2)* %cast
89 br label %endif
90
91endif:
92 %x = phi i32 [ %tmp1, %if ], [ 0, %entry ]
93 store i32 %x, i32 addrspace(4)* %out.gep
94 br label %done
95
96done:
97 ret void
98}