10bb25b46SAustin Kerbow; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 20bb25b46SAustin Kerbow; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s 30bb25b46SAustin Kerbow 4*26b14c3eSAustin Kerbow; Addrspacecasts or bitcasts must be inserted after the instructions that define their uses. 50bb25b46SAustin Kerbow 60bb25b46SAustin Kerbow%struct.s0 = type { i32*, i32 } 70bb25b46SAustin Kerbow%struct.s1 = type { %struct.s0 } 80bb25b46SAustin Kerbow 90bb25b46SAustin Kerbow@global0 = protected addrspace(4) externally_initialized global %struct.s1 zeroinitializer 100bb25b46SAustin Kerbow 110bb25b46SAustin Kerbowdeclare i32 @func(i32* %arg) 120bb25b46SAustin Kerbow 13*26b14c3eSAustin Kerbowdefine i32 @addrspacecast_insert_pos_assert() { 14*26b14c3eSAustin Kerbow; CHECK-LABEL: @addrspacecast_insert_pos_assert( 150bb25b46SAustin Kerbow; CHECK-NEXT: [[ALLOCA:%.*]] = alloca i32, align 4, addrspace(5) 160bb25b46SAustin Kerbow; CHECK-NEXT: [[LOAD0:%.*]] = load i32*, i32* addrspace(4)* getelementptr inbounds ([[STRUCT_S1:%.*]], [[STRUCT_S1]] addrspace(4)* @global0, i32 0, i32 0, i32 0), align 8 170bb25b46SAustin Kerbow; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast i32* [[LOAD0]] to i32 addrspace(1)* 180bb25b46SAustin Kerbow; CHECK-NEXT: [[TMP2:%.*]] = addrspacecast i32 addrspace(1)* [[TMP1]] to i32* 190bb25b46SAustin Kerbow; CHECK-NEXT: [[LOAD1:%.*]] = load i32, i32 addrspace(5)* [[ALLOCA]], align 4 200bb25b46SAustin Kerbow; CHECK-NEXT: [[SEXT:%.*]] = sext i32 [[LOAD1]] to i64 210bb25b46SAustin Kerbow; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 [[SEXT]] 220bb25b46SAustin Kerbow; CHECK-NEXT: [[CALL:%.*]] = call i32 @func(i32* [[GEP]]) 230bb25b46SAustin Kerbow; CHECK-NEXT: ret i32 [[CALL]] 240bb25b46SAustin Kerbow; 250bb25b46SAustin Kerbow %alloca = alloca i32, align 4, addrspace(5) 260bb25b46SAustin Kerbow %cast = addrspacecast i32 addrspace(5)* %alloca to i32* 270bb25b46SAustin Kerbow %load0 = load i32*, i32* addrspace(4)* getelementptr inbounds (%struct.s1, %struct.s1 addrspace(4)* @global0, i32 0, i32 0, i32 0) 280bb25b46SAustin Kerbow %load1 = load i32, i32* %cast 290bb25b46SAustin Kerbow %sext = sext i32 %load1 to i64 300bb25b46SAustin Kerbow %gep = getelementptr inbounds i32, i32* %load0, i64 %sext 310bb25b46SAustin Kerbow %call = call i32 @func(i32* %gep) 320bb25b46SAustin Kerbow ret i32 %call 330bb25b46SAustin Kerbow} 34*26b14c3eSAustin Kerbow 35*26b14c3eSAustin Kerbowdefine void @bitcast_insert_pos_assert_1() { 36*26b14c3eSAustin Kerbow; CHECK-LABEL: @bitcast_insert_pos_assert_1( 37*26b14c3eSAustin Kerbow; CHECK-NEXT: bb.0: 38*26b14c3eSAustin Kerbow; CHECK-NEXT: [[ASC0:%.*]] = bitcast [[STRUCT_S1:%.*]] addrspace(5)* undef to i8 addrspace(5)* 39*26b14c3eSAustin Kerbow; CHECK-NEXT: [[BC0:%.*]] = bitcast i8 addrspace(5)* [[ASC0]] to [[STRUCT_S1]] addrspace(5)* 40*26b14c3eSAustin Kerbow; CHECK-NEXT: [[TMP0:%.*]] = bitcast [[STRUCT_S1]] addrspace(5)* [[BC0]] to double* addrspace(5)* 41*26b14c3eSAustin Kerbow; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast double* addrspace(5)* [[TMP0]] to %struct.s1* 42*26b14c3eSAustin Kerbow; CHECK-NEXT: [[PTI0:%.*]] = ptrtoint %struct.s1* [[TMP1]] to i64 43*26b14c3eSAustin Kerbow; CHECK-NEXT: br label [[BB_1:%.*]] 44*26b14c3eSAustin Kerbow; CHECK: bb.1: 45*26b14c3eSAustin Kerbow; CHECK-NEXT: br i1 undef, label [[BB_2:%.*]], label [[BB_3:%.*]] 46*26b14c3eSAustin Kerbow; CHECK: bb.2: 47*26b14c3eSAustin Kerbow; CHECK-NEXT: [[LOAD0:%.*]] = load double*, double* addrspace(5)* [[TMP0]], align 8 48*26b14c3eSAustin Kerbow; CHECK-NEXT: br label [[BB_3]] 49*26b14c3eSAustin Kerbow; CHECK: bb.3: 50*26b14c3eSAustin Kerbow; CHECK-NEXT: ret void 51*26b14c3eSAustin Kerbow; 52*26b14c3eSAustin Kerbowbb.0: 53*26b14c3eSAustin Kerbow %asc0 = addrspacecast %struct.s1 addrspace(5)* undef to i8* 54*26b14c3eSAustin Kerbow %bc0 = bitcast i8* %asc0 to %struct.s1* 55*26b14c3eSAustin Kerbow %pti0 = ptrtoint %struct.s1* %bc0 to i64 56*26b14c3eSAustin Kerbow br label %bb.1 57*26b14c3eSAustin Kerbow 58*26b14c3eSAustin Kerbowbb.1: 59*26b14c3eSAustin Kerbow br i1 undef, label %bb.2, label %bb.3 60*26b14c3eSAustin Kerbow 61*26b14c3eSAustin Kerbowbb.2: 62*26b14c3eSAustin Kerbow %pti1 = ptrtoint %struct.s1* %bc0 to i64 63*26b14c3eSAustin Kerbow %itp0 = inttoptr i64 %pti1 to double** 64*26b14c3eSAustin Kerbow %load0 = load double*, double** %itp0, align 8 65*26b14c3eSAustin Kerbow br label %bb.3 66*26b14c3eSAustin Kerbow 67*26b14c3eSAustin Kerbowbb.3: 68*26b14c3eSAustin Kerbow ret void 69*26b14c3eSAustin Kerbow} 70*26b14c3eSAustin Kerbow 71*26b14c3eSAustin Kerbowdefine void @bitcast_insert_pos_assert_2() { 72*26b14c3eSAustin Kerbow; CHECK-LABEL: @bitcast_insert_pos_assert_2( 73*26b14c3eSAustin Kerbow; CHECK-NEXT: [[ALLOCA0:%.*]] = alloca [[STRUCT_S1:%.*]], align 16, addrspace(5) 74*26b14c3eSAustin Kerbow; CHECK-NEXT: [[ASC0:%.*]] = bitcast [[STRUCT_S1]] addrspace(5)* [[ALLOCA0]] to i8 addrspace(5)* 75*26b14c3eSAustin Kerbow; CHECK-NEXT: [[BC0:%.*]] = bitcast i8 addrspace(5)* [[ASC0]] to [[STRUCT_S1]] addrspace(5)* 76*26b14c3eSAustin Kerbow; CHECK-NEXT: [[TMP1:%.*]] = bitcast [[STRUCT_S1]] addrspace(5)* [[BC0]] to i64 addrspace(5)* 77*26b14c3eSAustin Kerbow; CHECK-NEXT: [[TMP2:%.*]] = addrspacecast i64 addrspace(5)* [[TMP1]] to %struct.s1* 78*26b14c3eSAustin Kerbow; CHECK-NEXT: [[PTI0:%.*]] = ptrtoint %struct.s1* [[TMP2]] to i64 79*26b14c3eSAustin Kerbow; CHECK-NEXT: [[ITP0:%.*]] = inttoptr i64 [[PTI0]] to i64* 80*26b14c3eSAustin Kerbow; CHECK-NEXT: [[TMP3:%.*]] = addrspacecast i64 addrspace(5)* [[TMP1]] to i64* 81*26b14c3eSAustin Kerbow; CHECK-NEXT: [[GEP0:%.*]] = getelementptr i64, i64* [[TMP3]], i64 0 82*26b14c3eSAustin Kerbow; CHECK-NEXT: ret void 83*26b14c3eSAustin Kerbow; 84*26b14c3eSAustin Kerbow %alloca0 = alloca %struct.s1, align 16, addrspace(5) 85*26b14c3eSAustin Kerbow %asc0 = addrspacecast %struct.s1 addrspace(5)* %alloca0 to i8* 86*26b14c3eSAustin Kerbow %bc0 = bitcast i8* %asc0 to %struct.s1* 87*26b14c3eSAustin Kerbow %pti0 = ptrtoint %struct.s1* %bc0 to i64 88*26b14c3eSAustin Kerbow %itp0 = inttoptr i64 %pti0 to i64* 89*26b14c3eSAustin Kerbow %itp1 = ptrtoint %struct.s1* %bc0 to i64 90*26b14c3eSAustin Kerbow %itp2 = inttoptr i64 %itp1 to i64* 91*26b14c3eSAustin Kerbow %gep0 = getelementptr i64, i64* %itp2, i64 0 92*26b14c3eSAustin Kerbow ret void 93*26b14c3eSAustin Kerbow} 94