1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s 2 3; CHECK-LABEL: @icmp_flat_cmp_self( 4; CHECK: %cmp = icmp eq i32 addrspace(3)* %group.ptr.0, %group.ptr.0 5define 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 8 ret i1 %cmp 9} 10 11; CHECK-LABEL: @icmp_flat_flat_from_group( 12; CHECK: %cmp = icmp eq i32 addrspace(3)* %group.ptr.0, %group.ptr.1 13define 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 17 ret i1 %cmp 18} 19 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 24define 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 28 ret i1 %cmp 29} 30 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 34define 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 37 ret i1 %cmp 38} 39 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 43define 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 46 ret i1 %cmp 47} 48 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 54define 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 58 ret i1 %cmp 59} 60 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. 63 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)*) 66define 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 69 ret i1 %cmp 70} 71 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)*) 74define 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*) 77 ret i1 %cmp 78} 79 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*) 83define 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*) 86 ret i1 %cmp 87} 88 89; CHECK-LABEL: @icmp_mismatch_flat_group_private_cmp_undef( 90; CHECK: %cmp = icmp eq i32 addrspace(3)* %group.ptr.0, undef 91define 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*) 94 ret i1 %cmp 95} 96 97@lds0 = internal addrspace(3) global i32 0, align 4 98@global0 = internal addrspace(1) global i32 0, align 4 99 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*) 103define 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*) 106 ret i1 %cmp 107} 108 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*) 111define 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*) 113 ret i1 %cmp 114} 115 116; CHECK-LABEL: @icmp_group_flat_cmp_undef( 117; CHECK: %cmp = icmp eq i32 addrspace(3)* %group.ptr.0, undef 118define 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 121 ret i1 %cmp 122} 123 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 128define 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 131 ret i1 %cmp 132} 133 134; CHECK-LABEL: @icmp_group_flat_cmp_undef_swap( 135; CHECK: %cmp = icmp eq i32 addrspace(3)* undef, %group.ptr.0 136define 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 139 ret i1 %cmp 140} 141 142; CHECK-LABEL: @icmp_mismatch_flat_group_private_cmp_undef_swap( 143; CHECK: %cmp = icmp eq i32 addrspace(3)* undef, %group.ptr.0 144define 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 147 ret i1 %cmp 148} 149 150; TODO: Should be handled 151; CHECK-LABEL: @icmp_flat_flat_from_group_vector( 152; CHECK: %cmp = icmp eq <2 x i32*> %cast0, %cast1 153define <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 157 ret <2 x i1> %cmp 158} 159 160attributes #0 = { nounwind } 161