1; RUN: opt -S -mtriple=amdgcn-amd-amdhsa -infer-address-spaces %s | FileCheck %s 2 3; Test that pure GetElementPtr instructions not directly connected to 4; a memory operation are inferred. 5 6@lds = internal unnamed_addr addrspace(3) global [648 x double] undef, align 8 7 8; CHECK-LABEL: @simplified_constexpr_gep_addrspacecast( 9; CHECK: %gep0 = getelementptr inbounds double, double addrspace(3)* getelementptr inbounds ([648 x double], [648 x double] addrspace(3)* @lds, i64 0, i64 384), i64 %idx0 10; CHECK-NEXT: store double 1.000000e+00, double addrspace(3)* %gep0, align 8 11define void @simplified_constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) { 12 %gep0 = getelementptr inbounds double, double* addrspacecast (double addrspace(3)* getelementptr inbounds ([648 x double], [648 x double] addrspace(3)* @lds, i64 0, i64 384) to double*), i64 %idx0 13 %asc = addrspacecast double* %gep0 to double addrspace(3)* 14 store double 1.000000e+00, double addrspace(3)* %asc, align 8 15 ret void 16} 17 18; CHECK-LABEL: @constexpr_gep_addrspacecast( 19; CHECK-NEXT: %gep0 = getelementptr inbounds double, double addrspace(3)* getelementptr inbounds ([648 x double], [648 x double] addrspace(3)* @lds, i64 0, i64 384), i64 %idx0 20; CHECK-NEXT: store double 1.000000e+00, double addrspace(3)* %gep0, align 8 21define void @constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) { 22 %gep0 = getelementptr inbounds double, double* getelementptr ([648 x double], [648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*), i64 0, i64 384), i64 %idx0 23 %asc = addrspacecast double* %gep0 to double addrspace(3)* 24 store double 1.0, double addrspace(3)* %asc, align 8 25 ret void 26} 27 28; CHECK-LABEL: @constexpr_gep_gep_addrspacecast( 29; CHECK: %gep0 = getelementptr inbounds double, double addrspace(3)* getelementptr inbounds ([648 x double], [648 x double] addrspace(3)* @lds, i64 0, i64 384), i64 %idx0 30; CHECK-NEXT: %gep1 = getelementptr inbounds double, double addrspace(3)* %gep0, i64 %idx1 31; CHECK-NEXT: store double 1.000000e+00, double addrspace(3)* %gep1, align 8 32define void @constexpr_gep_gep_addrspacecast(i64 %idx0, i64 %idx1) { 33 %gep0 = getelementptr inbounds double, double* getelementptr ([648 x double], [648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*), i64 0, i64 384), i64 %idx0 34 %gep1 = getelementptr inbounds double, double* %gep0, i64 %idx1 35 %asc = addrspacecast double* %gep1 to double addrspace(3)* 36 store double 1.0, double addrspace(3)* %asc, align 8 37 ret void 38} 39 40; Don't crash 41; CHECK-LABEL: @vector_gep( 42; CHECK: %cast = addrspacecast <4 x [1024 x i32] addrspace(3)*> %array to <4 x [1024 x i32]*> 43define amdgpu_kernel void @vector_gep(<4 x [1024 x i32] addrspace(3)*> %array) nounwind { 44 %cast = addrspacecast <4 x [1024 x i32] addrspace(3)*> %array to <4 x [1024 x i32]*> 45 %p = getelementptr [1024 x i32], <4 x [1024 x i32]*> %cast, <4 x i16> zeroinitializer, <4 x i16> <i16 16, i16 16, i16 16, i16 16> 46 %p0 = extractelement <4 x i32*> %p, i32 0 47 %p1 = extractelement <4 x i32*> %p, i32 1 48 %p2 = extractelement <4 x i32*> %p, i32 2 49 %p3 = extractelement <4 x i32*> %p, i32 3 50 store i32 99, i32* %p0 51 store i32 99, i32* %p1 52 store i32 99, i32* %p2 53 store i32 99, i32* %p3 54 ret void 55} 56 57; CHECK-LABEL: @repeated_constexpr_gep_addrspacecast( 58; CHECK-NEXT: %gep0 = getelementptr inbounds double, double addrspace(3)* getelementptr inbounds ([648 x double], [648 x double] addrspace(3)* @lds, i64 0, i64 384), i64 %idx0 59; CHECK-NEXT: store double 1.000000e+00, double addrspace(3)* %gep0, align 8 60; CHECK-NEXT: %gep1 = getelementptr inbounds double, double addrspace(3)* getelementptr inbounds ([648 x double], [648 x double] addrspace(3)* @lds, i64 0, i64 384), i64 %idx1 61; CHECK-NEXT: store double 1.000000e+00, double addrspace(3)* %gep1, align 8 62; CHECK-NEXT: ret void 63define void @repeated_constexpr_gep_addrspacecast(i64 %idx0, i64 %idx1) { 64 %gep0 = getelementptr inbounds double, double* getelementptr ([648 x double], [648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*), i64 0, i64 384), i64 %idx0 65 %asc0 = addrspacecast double* %gep0 to double addrspace(3)* 66 store double 1.0, double addrspace(3)* %asc0, align 8 67 68 %gep1 = getelementptr inbounds double, double* getelementptr ([648 x double], [648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*), i64 0, i64 384), i64 %idx1 69 %asc1 = addrspacecast double* %gep1 to double addrspace(3)* 70 store double 1.0, double addrspace(3)* %asc1, align 8 71 72 ret void 73} 74 75; CHECK-LABEL: @unorder_constexpr_gep_bitcast( 76; CHECK-NEXT: %x0 = load i32, i32 addrspace(3)* bitcast ([648 x double] addrspace(3)* @lds to i32 addrspace(3)*), align 4 77; CHECK-NEXT: %x1 = load i32, i32 addrspace(3)* getelementptr (i32, i32 addrspace(3)* bitcast ([648 x double] addrspace(3)* @lds to i32 addrspace(3)*), i32 1), align 4 78define void @unorder_constexpr_gep_bitcast() { 79 %x0 = load i32, i32* bitcast ([648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*) to i32*), align 4 80 %x1 = load i32, i32* getelementptr (i32, i32* bitcast ([648 x double]* addrspacecast ([648 x double] addrspace(3)* @lds to [648 x double]*) to i32*), i32 1), align 4 81 call void @use(i32 %x0, i32 %x1) 82 ret void 83} 84 85declare void @use(i32, i32) 86