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