1 ; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -passes=infer-address-spaces %s | FileCheck %s
3 ; CHECK-LABEL: @icmp_flat_cmp_self(
4 ; CHECK: %cmp = icmp eq ptr addrspace(3) %group.ptr.0, %group.ptr.0
5 define i1 @icmp_flat_cmp_self(ptr addrspace(3) %group.ptr.0) #0 {
6 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
7 %cmp = icmp eq ptr %cast0, %cast0
11 ; CHECK-LABEL: @icmp_flat_flat_from_group(
12 ; CHECK: %cmp = icmp eq ptr addrspace(3) %group.ptr.0, %group.ptr.1
13 define i1 @icmp_flat_flat_from_group(ptr addrspace(3) %group.ptr.0, ptr addrspace(3) %group.ptr.1) #0 {
14 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
15 %cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
16 %cmp = icmp eq ptr %cast0, %cast1
20 ; CHECK-LABEL: @icmp_mismatch_flat_from_group_private(
21 ; CHECK: %cast0 = addrspacecast ptr addrspace(5) %private.ptr.0 to ptr
22 ; CHECK: %cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
23 ; CHECK: %cmp = icmp eq ptr %cast0, %cast1
24 define i1 @icmp_mismatch_flat_from_group_private(ptr addrspace(5) %private.ptr.0, ptr addrspace(3) %group.ptr.1) #0 {
25 %cast0 = addrspacecast ptr addrspace(5) %private.ptr.0 to ptr
26 %cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
27 %cmp = icmp eq ptr %cast0, %cast1
31 ; CHECK-LABEL: @icmp_flat_group_flat(
32 ; CHECK: %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
33 ; CHECK: %cmp = icmp eq ptr %cast0, %flat.ptr.1
34 define i1 @icmp_flat_group_flat(ptr addrspace(3) %group.ptr.0, ptr %flat.ptr.1) #0 {
35 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
36 %cmp = icmp eq ptr %cast0, %flat.ptr.1
40 ; CHECK-LABEL: @icmp_flat_flat_group(
41 ; CHECK: %cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
42 ; CHECK: %cmp = icmp eq ptr %flat.ptr.0, %cast1
43 define i1 @icmp_flat_flat_group(ptr %flat.ptr.0, ptr addrspace(3) %group.ptr.1) #0 {
44 %cast1 = addrspacecast ptr addrspace(3) %group.ptr.1 to ptr
45 %cmp = icmp eq ptr %flat.ptr.0, %cast1
49 ; Keeping as cmp addrspace(3)* is better
50 ; CHECK-LABEL: @icmp_flat_to_group_cmp(
51 ; CHECK: %cast0 = addrspacecast ptr %flat.ptr.0 to ptr addrspace(3)
52 ; CHECK: %cast1 = addrspacecast ptr %flat.ptr.1 to ptr addrspace(3)
53 ; CHECK: %cmp = icmp eq ptr addrspace(3) %cast0, %cast1
54 define i1 @icmp_flat_to_group_cmp(ptr %flat.ptr.0, ptr %flat.ptr.1) #0 {
55 %cast0 = addrspacecast ptr %flat.ptr.0 to ptr addrspace(3)
56 %cast1 = addrspacecast ptr %flat.ptr.1 to ptr addrspace(3)
57 %cmp = icmp eq ptr addrspace(3) %cast0, %cast1
61 ; FIXME: Should be able to ask target about how to constant fold the
62 ; constant cast if this is OK to change if 0 is a valid pointer.
64 ; CHECK-LABEL: @icmp_group_flat_cmp_null(
65 ; CHECK: %cmp = icmp eq ptr addrspace(3) %group.ptr.0, addrspacecast (ptr null to ptr addrspace(3))
66 define i1 @icmp_group_flat_cmp_null(ptr addrspace(3) %group.ptr.0) #0 {
67 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
68 %cmp = icmp eq ptr %cast0, null
72 ; CHECK-LABEL: @icmp_group_flat_cmp_constant_inttoptr(
73 ; CHECK: %cmp = icmp eq ptr addrspace(3) %group.ptr.0, addrspacecast (ptr inttoptr (i64 400 to ptr) to ptr addrspace(3))
74 define i1 @icmp_group_flat_cmp_constant_inttoptr(ptr addrspace(3) %group.ptr.0) #0 {
75 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
76 %cmp = icmp eq ptr %cast0, inttoptr (i64 400 to ptr)
80 ; CHECK-LABEL: @icmp_mismatch_flat_group_private_cmp_null(
81 ; CHECK: %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
82 ; CHECK: %cmp = icmp eq ptr %cast0, addrspacecast (ptr addrspace(5) null to ptr)
83 define i1 @icmp_mismatch_flat_group_private_cmp_null(ptr addrspace(3) %group.ptr.0) #0 {
84 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
85 %cmp = icmp eq ptr %cast0, addrspacecast (ptr addrspace(5) null to ptr)
89 ; CHECK-LABEL: @icmp_mismatch_flat_group_private_cmp_undef(
90 ; CHECK: %cmp = icmp eq ptr addrspace(3) %group.ptr.0, undef
91 define i1 @icmp_mismatch_flat_group_private_cmp_undef(ptr addrspace(3) %group.ptr.0) #0 {
92 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
93 %cmp = icmp eq ptr %cast0, addrspacecast (ptr addrspace(5) undef to ptr)
97 @lds0 = internal addrspace(3) global i32 0, align 4
98 @global0 = internal addrspace(1) global i32 0, align 4
100 ; CHECK-LABEL: @icmp_mismatch_flat_group_global_cmp_gv(
101 ; CHECK: %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
102 ; CHECK: %cmp = icmp eq ptr %cast0, addrspacecast (ptr addrspace(1) @global0 to ptr)
103 define i1 @icmp_mismatch_flat_group_global_cmp_gv(ptr addrspace(3) %group.ptr.0) #0 {
104 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
105 %cmp = icmp eq ptr %cast0, addrspacecast (ptr addrspace(1) @global0 to ptr)
109 ; CHECK-LABEL: @icmp_mismatch_group_global_cmp_gv_gv(
110 ; CHECK: %cmp = icmp eq ptr addrspacecast (ptr addrspace(3) @lds0 to ptr), addrspacecast (ptr addrspace(1) @global0 to ptr)
111 define i1 @icmp_mismatch_group_global_cmp_gv_gv(ptr addrspace(3) %group.ptr.0) #0 {
112 %cmp = icmp eq ptr addrspacecast (ptr addrspace(3) @lds0 to ptr), addrspacecast (ptr addrspace(1) @global0 to ptr)
116 ; CHECK-LABEL: @icmp_group_flat_cmp_undef(
117 ; CHECK: %cmp = icmp eq ptr addrspace(3) %group.ptr.0, undef
118 define i1 @icmp_group_flat_cmp_undef(ptr addrspace(3) %group.ptr.0) #0 {
119 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
120 %cmp = icmp eq ptr %cast0, undef
124 ; Test non-canonical orders
125 ; CHECK-LABEL: @icmp_mismatch_flat_group_private_cmp_null_swap(
126 ; CHECK: %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
127 ; CHECK: %cmp = icmp eq ptr addrspacecast (ptr addrspace(5) null to ptr), %cast0
128 define i1 @icmp_mismatch_flat_group_private_cmp_null_swap(ptr addrspace(3) %group.ptr.0) #0 {
129 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
130 %cmp = icmp eq ptr addrspacecast (ptr addrspace(5) null to ptr), %cast0
134 ; CHECK-LABEL: @icmp_group_flat_cmp_undef_swap(
135 ; CHECK: %cmp = icmp eq ptr addrspace(3) undef, %group.ptr.0
136 define i1 @icmp_group_flat_cmp_undef_swap(ptr addrspace(3) %group.ptr.0) #0 {
137 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
138 %cmp = icmp eq ptr undef, %cast0
142 ; CHECK-LABEL: @icmp_mismatch_flat_group_private_cmp_undef_swap(
143 ; CHECK: %cmp = icmp eq ptr addrspace(3) undef, %group.ptr.0
144 define i1 @icmp_mismatch_flat_group_private_cmp_undef_swap(ptr addrspace(3) %group.ptr.0) #0 {
145 %cast0 = addrspacecast ptr addrspace(3) %group.ptr.0 to ptr
146 %cmp = icmp eq ptr addrspacecast (ptr addrspace(5) undef to ptr), %cast0
150 ; CHECK-LABEL: @icmp_flat_flat_from_group_vector(
151 ; CHECK: %cmp = icmp eq <2 x ptr addrspace(3)> %group.ptr.0, %group.ptr.1
152 define <2 x i1> @icmp_flat_flat_from_group_vector(<2 x ptr addrspace(3)> %group.ptr.0, <2 x ptr addrspace(3)> %group.ptr.1) #0 {
153 %cast0 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.0 to <2 x ptr>
154 %cast1 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.1 to <2 x ptr>
155 %cmp = icmp eq <2 x ptr> %cast0, %cast1
159 attributes #0 = { nounwind }