1*0bb25b46SAustin Kerbow; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2*0bb25b46SAustin Kerbow; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s 3*0bb25b46SAustin Kerbow 4*0bb25b46SAustin Kerbow; Addrspacecasts must be inserted after the instructions that define their uses. 5*0bb25b46SAustin Kerbow 6*0bb25b46SAustin Kerbow%struct.s0 = type { i32*, i32 } 7*0bb25b46SAustin Kerbow%struct.s1 = type { %struct.s0 } 8*0bb25b46SAustin Kerbow 9*0bb25b46SAustin Kerbow@global0 = protected addrspace(4) externally_initialized global %struct.s1 zeroinitializer 10*0bb25b46SAustin Kerbow 11*0bb25b46SAustin Kerbowdeclare i32 @func(i32* %arg) 12*0bb25b46SAustin Kerbow 13*0bb25b46SAustin Kerbowdefine i32 @insert_pos_assert() { 14*0bb25b46SAustin Kerbow; CHECK-LABEL: @insert_pos_assert( 15*0bb25b46SAustin Kerbow; CHECK-NEXT: [[ALLOCA:%.*]] = alloca i32, align 4, addrspace(5) 16*0bb25b46SAustin 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 17*0bb25b46SAustin Kerbow; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast i32* [[LOAD0]] to i32 addrspace(1)* 18*0bb25b46SAustin Kerbow; CHECK-NEXT: [[TMP2:%.*]] = addrspacecast i32 addrspace(1)* [[TMP1]] to i32* 19*0bb25b46SAustin Kerbow; CHECK-NEXT: [[LOAD1:%.*]] = load i32, i32 addrspace(5)* [[ALLOCA]], align 4 20*0bb25b46SAustin Kerbow; CHECK-NEXT: [[SEXT:%.*]] = sext i32 [[LOAD1]] to i64 21*0bb25b46SAustin Kerbow; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds i32, i32* [[TMP2]], i64 [[SEXT]] 22*0bb25b46SAustin Kerbow; CHECK-NEXT: [[CALL:%.*]] = call i32 @func(i32* [[GEP]]) 23*0bb25b46SAustin Kerbow; CHECK-NEXT: ret i32 [[CALL]] 24*0bb25b46SAustin Kerbow; 25*0bb25b46SAustin Kerbow %alloca = alloca i32, align 4, addrspace(5) 26*0bb25b46SAustin Kerbow %cast = addrspacecast i32 addrspace(5)* %alloca to i32* 27*0bb25b46SAustin Kerbow %load0 = load i32*, i32* addrspace(4)* getelementptr inbounds (%struct.s1, %struct.s1 addrspace(4)* @global0, i32 0, i32 0, i32 0) 28*0bb25b46SAustin Kerbow %load1 = load i32, i32* %cast 29*0bb25b46SAustin Kerbow %sext = sext i32 %load1 to i64 30*0bb25b46SAustin Kerbow %gep = getelementptr inbounds i32, i32* %load0, i64 %sext 31*0bb25b46SAustin Kerbow %call = call i32 @func(i32* %gep) 32*0bb25b46SAustin Kerbow ret i32 %call 33*0bb25b46SAustin Kerbow} 34