1*23dcd6e0SJan Vesely; RUN: llc -march=r600 -mcpu=cypress < %s | FileCheck %s -check-prefix=R600 -check-prefix=FUNC 2*23dcd6e0SJan Vesely; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -march=amdgcn < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC 3*23dcd6e0SJan Vesely; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -mtriple=amdgcn--amdhsa -mcpu=kaveri < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC -check-prefix=HSA-PROMOTE 4*23dcd6e0SJan Vesely; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -march=amdgcn < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC 5*23dcd6e0SJan Vesely; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -mtriple=amdgcn-amdhsa -mcpu=kaveri < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC -check-prefix=HSA-ALLOCA 6*23dcd6e0SJan Vesely; RUN: llc -show-mc-encoding -mattr=+promote-alloca -verify-machineinstrs -march=amdgcn -mcpu=tonga < %s | FileCheck %s -check-prefix=SI-PROMOTE -check-prefix=SI -check-prefix=FUNC 7*23dcd6e0SJan Vesely; RUN: llc -show-mc-encoding -mattr=-promote-alloca -verify-machineinstrs -march=amdgcn -mcpu=tonga < %s | FileCheck %s -check-prefix=SI-ALLOCA -check-prefix=SI -check-prefix=FUNC 8*23dcd6e0SJan Vesely 9*23dcd6e0SJan Vesely; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck -check-prefix=HSAOPT -check-prefix=OPT %s 10*23dcd6e0SJan Vesely; RUN: opt -S -mtriple=amdgcn-unknown-unknown -mcpu=kaveri -amdgpu-promote-alloca < %s | FileCheck -check-prefix=NOHSAOPT -check-prefix=OPT %s 11*23dcd6e0SJan Vesely 12*23dcd6e0SJan Vesely; HSAOPT: @mova_same_clause.stack = internal unnamed_addr addrspace(3) global [256 x [5 x i32]] undef, align 4 13*23dcd6e0SJan Vesely; HSAOPT: @high_alignment.stack = internal unnamed_addr addrspace(3) global [256 x [8 x i32]] undef, align 16 14*23dcd6e0SJan Vesely 15*23dcd6e0SJan Vesely 16*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}mova_same_clause: 17*23dcd6e0SJan Vesely; OPT-LABEL: @mova_same_clause( 18*23dcd6e0SJan Vesely 19*23dcd6e0SJan Vesely; R600: LDS_WRITE 20*23dcd6e0SJan Vesely; R600: LDS_WRITE 21*23dcd6e0SJan Vesely; R600: LDS_READ 22*23dcd6e0SJan Vesely; R600: LDS_READ 23*23dcd6e0SJan Vesely 24*23dcd6e0SJan Vesely; HSA-PROMOTE: .amd_kernel_code_t 25*23dcd6e0SJan Vesely; HSA-PROMOTE: workgroup_group_segment_byte_size = 5120 26*23dcd6e0SJan Vesely; HSA-PROMOTE: .end_amd_kernel_code_t 27*23dcd6e0SJan Vesely 28*23dcd6e0SJan Vesely; FIXME: These should be merged 29*23dcd6e0SJan Vesely; HSA-PROMOTE: s_load_dword s{{[0-9]+}}, s[4:5], 0x1 30*23dcd6e0SJan Vesely; HSA-PROMOTE: s_load_dword s{{[0-9]+}}, s[4:5], 0x2 31*23dcd6e0SJan Vesely 32*23dcd6e0SJan Vesely; SI-PROMOTE: ds_write_b32 33*23dcd6e0SJan Vesely; SI-PROMOTE: ds_write_b32 34*23dcd6e0SJan Vesely; SI-PROMOTE: ds_read_b32 35*23dcd6e0SJan Vesely; SI-PROMOTE: ds_read_b32 36*23dcd6e0SJan Vesely 37*23dcd6e0SJan Vesely; HSA-ALLOCA: .amd_kernel_code_t 38*23dcd6e0SJan Vesely; FIXME: Creating the emergency stack slots causes us to over-estimate scratch 39*23dcd6e0SJan Vesely; by 4 bytes. 40*23dcd6e0SJan Vesely; HSA-ALLOCA: workitem_private_segment_byte_size = 24 41*23dcd6e0SJan Vesely; HSA-ALLOCA: .end_amd_kernel_code_t 42*23dcd6e0SJan Vesely 43*23dcd6e0SJan Vesely; HSA-ALLOCA: s_mov_b32 flat_scratch_lo, s7 44*23dcd6e0SJan Vesely; HSA-ALLOCA: s_add_u32 s6, s6, s9 45*23dcd6e0SJan Vesely; HSA-ALLOCA: s_lshr_b32 flat_scratch_hi, s6, 8 46*23dcd6e0SJan Vesely 47*23dcd6e0SJan Vesely; SI-ALLOCA: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x70,0xe0 48*23dcd6e0SJan Vesely; SI-ALLOCA: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x70,0xe0 49*23dcd6e0SJan Vesely 50*23dcd6e0SJan Vesely 51*23dcd6e0SJan Vesely; HSAOPT: [[DISPATCH_PTR:%[0-9]+]] = call noalias nonnull dereferenceable(64) i8 addrspace(2)* @llvm.amdgcn.dispatch.ptr() 52*23dcd6e0SJan Vesely; HSAOPT: [[CAST_DISPATCH_PTR:%[0-9]+]] = bitcast i8 addrspace(2)* [[DISPATCH_PTR]] to i32 addrspace(2)* 53*23dcd6e0SJan Vesely; HSAOPT: [[GEP0:%[0-9]+]] = getelementptr inbounds i32, i32 addrspace(2)* [[CAST_DISPATCH_PTR]], i64 1 54*23dcd6e0SJan Vesely; HSAOPT: [[LDXY:%[0-9]+]] = load i32, i32 addrspace(2)* [[GEP0]], align 4, !invariant.load !0 55*23dcd6e0SJan Vesely; HSAOPT: [[GEP1:%[0-9]+]] = getelementptr inbounds i32, i32 addrspace(2)* [[CAST_DISPATCH_PTR]], i64 2 56*23dcd6e0SJan Vesely; HSAOPT: [[LDZU:%[0-9]+]] = load i32, i32 addrspace(2)* [[GEP1]], align 4, !range !1, !invariant.load !0 57*23dcd6e0SJan Vesely; HSAOPT: [[EXTRACTY:%[0-9]+]] = lshr i32 [[LDXY]], 16 58*23dcd6e0SJan Vesely 59*23dcd6e0SJan Vesely; HSAOPT: [[WORKITEM_ID_X:%[0-9]+]] = call i32 @llvm.amdgcn.workitem.id.x(), !range !1 60*23dcd6e0SJan Vesely; HSAOPT: [[WORKITEM_ID_Y:%[0-9]+]] = call i32 @llvm.amdgcn.workitem.id.y(), !range !1 61*23dcd6e0SJan Vesely; HSAOPT: [[WORKITEM_ID_Z:%[0-9]+]] = call i32 @llvm.amdgcn.workitem.id.z(), !range !1 62*23dcd6e0SJan Vesely 63*23dcd6e0SJan Vesely; HSAOPT: [[Y_SIZE_X_Z_SIZE:%[0-9]+]] = mul nuw nsw i32 [[EXTRACTY]], [[LDZU]] 64*23dcd6e0SJan Vesely; HSAOPT: [[YZ_X_XID:%[0-9]+]] = mul i32 [[Y_SIZE_X_Z_SIZE]], [[WORKITEM_ID_X]] 65*23dcd6e0SJan Vesely; HSAOPT: [[Y_X_Z_SIZE:%[0-9]+]] = mul nuw nsw i32 [[WORKITEM_ID_Y]], [[LDZU]] 66*23dcd6e0SJan Vesely; HSAOPT: [[ADD_YZ_X_X_YZ_SIZE:%[0-9]+]] = add i32 [[YZ_X_XID]], [[Y_X_Z_SIZE]] 67*23dcd6e0SJan Vesely; HSAOPT: [[ADD_ZID:%[0-9]+]] = add i32 [[ADD_YZ_X_X_YZ_SIZE]], [[WORKITEM_ID_Z]] 68*23dcd6e0SJan Vesely 69*23dcd6e0SJan Vesely; HSAOPT: [[LOCAL_GEP:%[0-9]+]] = getelementptr inbounds [256 x [5 x i32]], [256 x [5 x i32]] addrspace(3)* @mova_same_clause.stack, i32 0, i32 [[ADD_ZID]] 70*23dcd6e0SJan Vesely; HSAOPT: %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 {{%[0-9]+}} 71*23dcd6e0SJan Vesely; HSAOPT: %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 {{%[0-9]+}} 72*23dcd6e0SJan Vesely; HSAOPT: %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 0 73*23dcd6e0SJan Vesely; HSAOPT: %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32] addrspace(3)* [[LOCAL_GEP]], i32 0, i32 1 74*23dcd6e0SJan Vesely 75*23dcd6e0SJan Vesely 76*23dcd6e0SJan Vesely; NOHSAOPT: call i32 @llvm.r600.read.local.size.y(), !range !0 77*23dcd6e0SJan Vesely; NOHSAOPT: call i32 @llvm.r600.read.local.size.z(), !range !0 78*23dcd6e0SJan Vesely; NOHSAOPT: call i32 @llvm.amdgcn.workitem.id.x(), !range !0 79*23dcd6e0SJan Vesely; NOHSAOPT: call i32 @llvm.amdgcn.workitem.id.y(), !range !0 80*23dcd6e0SJan Vesely; NOHSAOPT: call i32 @llvm.amdgcn.workitem.id.z(), !range !0 81*23dcd6e0SJan Veselydefine void @mova_same_clause(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) { 82*23dcd6e0SJan Veselyentry: 83*23dcd6e0SJan Vesely %stack = alloca [5 x i32], align 4 84*23dcd6e0SJan Vesely %0 = load i32, i32 addrspace(1)* %in, align 4 85*23dcd6e0SJan Vesely %arrayidx1 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %0 86*23dcd6e0SJan Vesely store i32 4, i32* %arrayidx1, align 4 87*23dcd6e0SJan Vesely %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1 88*23dcd6e0SJan Vesely %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4 89*23dcd6e0SJan Vesely %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %1 90*23dcd6e0SJan Vesely store i32 5, i32* %arrayidx3, align 4 91*23dcd6e0SJan Vesely %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 0 92*23dcd6e0SJan Vesely %2 = load i32, i32* %arrayidx10, align 4 93*23dcd6e0SJan Vesely store i32 %2, i32 addrspace(1)* %out, align 4 94*23dcd6e0SJan Vesely %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 1 95*23dcd6e0SJan Vesely %3 = load i32, i32* %arrayidx12 96*23dcd6e0SJan Vesely %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1 97*23dcd6e0SJan Vesely store i32 %3, i32 addrspace(1)* %arrayidx13 98*23dcd6e0SJan Vesely ret void 99*23dcd6e0SJan Vesely} 100*23dcd6e0SJan Vesely 101*23dcd6e0SJan Vesely; OPT-LABEL: @high_alignment( 102*23dcd6e0SJan Vesely; OPT: getelementptr inbounds [256 x [8 x i32]], [256 x [8 x i32]] addrspace(3)* @high_alignment.stack, i32 0, i32 %{{[0-9]+}} 103*23dcd6e0SJan Veselydefine void @high_alignment(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) { 104*23dcd6e0SJan Veselyentry: 105*23dcd6e0SJan Vesely %stack = alloca [8 x i32], align 16 106*23dcd6e0SJan Vesely %0 = load i32, i32 addrspace(1)* %in, align 4 107*23dcd6e0SJan Vesely %arrayidx1 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 %0 108*23dcd6e0SJan Vesely store i32 4, i32* %arrayidx1, align 4 109*23dcd6e0SJan Vesely %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1 110*23dcd6e0SJan Vesely %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4 111*23dcd6e0SJan Vesely %arrayidx3 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 %1 112*23dcd6e0SJan Vesely store i32 5, i32* %arrayidx3, align 4 113*23dcd6e0SJan Vesely %arrayidx10 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 0 114*23dcd6e0SJan Vesely %2 = load i32, i32* %arrayidx10, align 4 115*23dcd6e0SJan Vesely store i32 %2, i32 addrspace(1)* %out, align 4 116*23dcd6e0SJan Vesely %arrayidx12 = getelementptr inbounds [8 x i32], [8 x i32]* %stack, i32 0, i32 1 117*23dcd6e0SJan Vesely %3 = load i32, i32* %arrayidx12 118*23dcd6e0SJan Vesely %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1 119*23dcd6e0SJan Vesely store i32 %3, i32 addrspace(1)* %arrayidx13 120*23dcd6e0SJan Vesely ret void 121*23dcd6e0SJan Vesely} 122*23dcd6e0SJan Vesely 123*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}no_replace_inbounds_gep: 124*23dcd6e0SJan Vesely; OPT-LABEL: @no_replace_inbounds_gep( 125*23dcd6e0SJan Vesely; OPT: alloca [5 x i32] 126*23dcd6e0SJan Vesely 127*23dcd6e0SJan Vesely; SI-NOT: ds_write 128*23dcd6e0SJan Veselydefine void @no_replace_inbounds_gep(i32 addrspace(1)* nocapture %out, i32 addrspace(1)* nocapture %in) { 129*23dcd6e0SJan Veselyentry: 130*23dcd6e0SJan Vesely %stack = alloca [5 x i32], align 4 131*23dcd6e0SJan Vesely %0 = load i32, i32 addrspace(1)* %in, align 4 132*23dcd6e0SJan Vesely %arrayidx1 = getelementptr [5 x i32], [5 x i32]* %stack, i32 0, i32 %0 133*23dcd6e0SJan Vesely store i32 4, i32* %arrayidx1, align 4 134*23dcd6e0SJan Vesely %arrayidx2 = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1 135*23dcd6e0SJan Vesely %1 = load i32, i32 addrspace(1)* %arrayidx2, align 4 136*23dcd6e0SJan Vesely %arrayidx3 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 %1 137*23dcd6e0SJan Vesely store i32 5, i32* %arrayidx3, align 4 138*23dcd6e0SJan Vesely %arrayidx10 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 0 139*23dcd6e0SJan Vesely %2 = load i32, i32* %arrayidx10, align 4 140*23dcd6e0SJan Vesely store i32 %2, i32 addrspace(1)* %out, align 4 141*23dcd6e0SJan Vesely %arrayidx12 = getelementptr inbounds [5 x i32], [5 x i32]* %stack, i32 0, i32 1 142*23dcd6e0SJan Vesely %3 = load i32, i32* %arrayidx12 143*23dcd6e0SJan Vesely %arrayidx13 = getelementptr inbounds i32, i32 addrspace(1)* %out, i32 1 144*23dcd6e0SJan Vesely store i32 %3, i32 addrspace(1)* %arrayidx13 145*23dcd6e0SJan Vesely ret void 146*23dcd6e0SJan Vesely} 147*23dcd6e0SJan Vesely 148*23dcd6e0SJan Vesely; This test checks that the stack offset is calculated correctly for structs. 149*23dcd6e0SJan Vesely; All register loads/stores should be optimized away, so there shouldn't be 150*23dcd6e0SJan Vesely; any MOVA instructions. 151*23dcd6e0SJan Vesely; 152*23dcd6e0SJan Vesely; XXX: This generated code has unnecessary MOVs, we should be able to optimize 153*23dcd6e0SJan Vesely; this. 154*23dcd6e0SJan Vesely 155*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}multiple_structs: 156*23dcd6e0SJan Vesely; OPT-LABEL: @multiple_structs( 157*23dcd6e0SJan Vesely 158*23dcd6e0SJan Vesely; R600-NOT: MOVA_INT 159*23dcd6e0SJan Vesely; SI-NOT: v_movrel 160*23dcd6e0SJan Vesely; SI-NOT: v_movrel 161*23dcd6e0SJan Vesely%struct.point = type { i32, i32 } 162*23dcd6e0SJan Vesely 163*23dcd6e0SJan Veselydefine void @multiple_structs(i32 addrspace(1)* %out) { 164*23dcd6e0SJan Veselyentry: 165*23dcd6e0SJan Vesely %a = alloca %struct.point 166*23dcd6e0SJan Vesely %b = alloca %struct.point 167*23dcd6e0SJan Vesely %a.x.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 0 168*23dcd6e0SJan Vesely %a.y.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 1 169*23dcd6e0SJan Vesely %b.x.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 0 170*23dcd6e0SJan Vesely %b.y.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 1 171*23dcd6e0SJan Vesely store i32 0, i32* %a.x.ptr 172*23dcd6e0SJan Vesely store i32 1, i32* %a.y.ptr 173*23dcd6e0SJan Vesely store i32 2, i32* %b.x.ptr 174*23dcd6e0SJan Vesely store i32 3, i32* %b.y.ptr 175*23dcd6e0SJan Vesely %a.indirect.ptr = getelementptr %struct.point, %struct.point* %a, i32 0, i32 0 176*23dcd6e0SJan Vesely %b.indirect.ptr = getelementptr %struct.point, %struct.point* %b, i32 0, i32 0 177*23dcd6e0SJan Vesely %a.indirect = load i32, i32* %a.indirect.ptr 178*23dcd6e0SJan Vesely %b.indirect = load i32, i32* %b.indirect.ptr 179*23dcd6e0SJan Vesely %0 = add i32 %a.indirect, %b.indirect 180*23dcd6e0SJan Vesely store i32 %0, i32 addrspace(1)* %out 181*23dcd6e0SJan Vesely ret void 182*23dcd6e0SJan Vesely} 183*23dcd6e0SJan Vesely 184*23dcd6e0SJan Vesely; Test direct access of a private array inside a loop. The private array 185*23dcd6e0SJan Vesely; loads and stores should be lowered to copies, so there shouldn't be any 186*23dcd6e0SJan Vesely; MOVA instructions. 187*23dcd6e0SJan Vesely 188*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}direct_loop: 189*23dcd6e0SJan Vesely; R600-NOT: MOVA_INT 190*23dcd6e0SJan Vesely; SI-NOT: v_movrel 191*23dcd6e0SJan Vesely 192*23dcd6e0SJan Veselydefine void @direct_loop(i32 addrspace(1)* %out, i32 addrspace(1)* %in) { 193*23dcd6e0SJan Veselyentry: 194*23dcd6e0SJan Vesely %prv_array_const = alloca [2 x i32] 195*23dcd6e0SJan Vesely %prv_array = alloca [2 x i32] 196*23dcd6e0SJan Vesely %a = load i32, i32 addrspace(1)* %in 197*23dcd6e0SJan Vesely %b_src_ptr = getelementptr inbounds i32, i32 addrspace(1)* %in, i32 1 198*23dcd6e0SJan Vesely %b = load i32, i32 addrspace(1)* %b_src_ptr 199*23dcd6e0SJan Vesely %a_dst_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0 200*23dcd6e0SJan Vesely store i32 %a, i32* %a_dst_ptr 201*23dcd6e0SJan Vesely %b_dst_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 1 202*23dcd6e0SJan Vesely store i32 %b, i32* %b_dst_ptr 203*23dcd6e0SJan Vesely br label %for.body 204*23dcd6e0SJan Vesely 205*23dcd6e0SJan Veselyfor.body: 206*23dcd6e0SJan Vesely %inc = phi i32 [0, %entry], [%count, %for.body] 207*23dcd6e0SJan Vesely %x_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array_const, i32 0, i32 0 208*23dcd6e0SJan Vesely %x = load i32, i32* %x_ptr 209*23dcd6e0SJan Vesely %y_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0 210*23dcd6e0SJan Vesely %y = load i32, i32* %y_ptr 211*23dcd6e0SJan Vesely %xy = add i32 %x, %y 212*23dcd6e0SJan Vesely store i32 %xy, i32* %y_ptr 213*23dcd6e0SJan Vesely %count = add i32 %inc, 1 214*23dcd6e0SJan Vesely %done = icmp eq i32 %count, 4095 215*23dcd6e0SJan Vesely br i1 %done, label %for.end, label %for.body 216*23dcd6e0SJan Vesely 217*23dcd6e0SJan Veselyfor.end: 218*23dcd6e0SJan Vesely %value_ptr = getelementptr inbounds [2 x i32], [2 x i32]* %prv_array, i32 0, i32 0 219*23dcd6e0SJan Vesely %value = load i32, i32* %value_ptr 220*23dcd6e0SJan Vesely store i32 %value, i32 addrspace(1)* %out 221*23dcd6e0SJan Vesely ret void 222*23dcd6e0SJan Vesely} 223*23dcd6e0SJan Vesely 224*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}short_array: 225*23dcd6e0SJan Vesely 226*23dcd6e0SJan Vesely; R600: MOVA_INT 227*23dcd6e0SJan Vesely 228*23dcd6e0SJan Vesely; SI-PROMOTE-DAG: buffer_store_short v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x68,0xe0 229*23dcd6e0SJan Vesely; SI-PROMOTE-DAG: buffer_store_short v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:2 ; encoding: [0x02,0x10,0x68,0xe0 230*23dcd6e0SJan Vesely; SI-PROMOTE: buffer_load_sshort v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} 231*23dcd6e0SJan Veselydefine void @short_array(i32 addrspace(1)* %out, i32 %index) { 232*23dcd6e0SJan Veselyentry: 233*23dcd6e0SJan Vesely %0 = alloca [2 x i16] 234*23dcd6e0SJan Vesely %1 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 0 235*23dcd6e0SJan Vesely %2 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 1 236*23dcd6e0SJan Vesely store i16 0, i16* %1 237*23dcd6e0SJan Vesely store i16 1, i16* %2 238*23dcd6e0SJan Vesely %3 = getelementptr inbounds [2 x i16], [2 x i16]* %0, i32 0, i32 %index 239*23dcd6e0SJan Vesely %4 = load i16, i16* %3 240*23dcd6e0SJan Vesely %5 = sext i16 %4 to i32 241*23dcd6e0SJan Vesely store i32 %5, i32 addrspace(1)* %out 242*23dcd6e0SJan Vesely ret void 243*23dcd6e0SJan Vesely} 244*23dcd6e0SJan Vesely 245*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}char_array: 246*23dcd6e0SJan Vesely 247*23dcd6e0SJan Vesely; R600: MOVA_INT 248*23dcd6e0SJan Vesely 249*23dcd6e0SJan Vesely; SI-DAG: buffer_store_byte v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen ; encoding: [0x00,0x10,0x60,0xe0 250*23dcd6e0SJan Vesely; SI-DAG: buffer_store_byte v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:1 ; encoding: [0x01,0x10,0x60,0xe0 251*23dcd6e0SJan Veselydefine void @char_array(i32 addrspace(1)* %out, i32 %index) { 252*23dcd6e0SJan Veselyentry: 253*23dcd6e0SJan Vesely %0 = alloca [2 x i8] 254*23dcd6e0SJan Vesely %1 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 0 255*23dcd6e0SJan Vesely %2 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 1 256*23dcd6e0SJan Vesely store i8 0, i8* %1 257*23dcd6e0SJan Vesely store i8 1, i8* %2 258*23dcd6e0SJan Vesely %3 = getelementptr inbounds [2 x i8], [2 x i8]* %0, i32 0, i32 %index 259*23dcd6e0SJan Vesely %4 = load i8, i8* %3 260*23dcd6e0SJan Vesely %5 = sext i8 %4 to i32 261*23dcd6e0SJan Vesely store i32 %5, i32 addrspace(1)* %out 262*23dcd6e0SJan Vesely ret void 263*23dcd6e0SJan Vesely 264*23dcd6e0SJan Vesely} 265*23dcd6e0SJan Vesely 266*23dcd6e0SJan Vesely 267*23dcd6e0SJan Vesely; Test that two stack objects are not stored in the same register 268*23dcd6e0SJan Vesely; The second stack object should be in T3.X 269*23dcd6e0SJan Vesely; FUNC-LABEL: {{^}}no_overlap: 270*23dcd6e0SJan Vesely; R600_CHECK: MOV 271*23dcd6e0SJan Vesely; R600_CHECK: [[CHAN:[XYZW]]]+ 272*23dcd6e0SJan Vesely; R600-NOT: [[CHAN]]+ 273*23dcd6e0SJan Vesely; SI: v_mov_b32_e32 v3 274*23dcd6e0SJan Veselydefine void @no_overlap(i32 addrspace(1)* %out, i32 %in) { 275*23dcd6e0SJan Veselyentry: 276*23dcd6e0SJan Vesely %0 = alloca [3 x i8], align 1 277*23dcd6e0SJan Vesely %1 = alloca [2 x i8], align 1 278*23dcd6e0SJan Vesely %2 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 0 279*23dcd6e0SJan Vesely %3 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 1 280*23dcd6e0SJan Vesely %4 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 2 281*23dcd6e0SJan Vesely %5 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 0 282*23dcd6e0SJan Vesely %6 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 1 283*23dcd6e0SJan Vesely store i8 0, i8* %2 284*23dcd6e0SJan Vesely store i8 1, i8* %3 285*23dcd6e0SJan Vesely store i8 2, i8* %4 286*23dcd6e0SJan Vesely store i8 1, i8* %5 287*23dcd6e0SJan Vesely store i8 0, i8* %6 288*23dcd6e0SJan Vesely %7 = getelementptr [3 x i8], [3 x i8]* %0, i32 0, i32 %in 289*23dcd6e0SJan Vesely %8 = getelementptr [2 x i8], [2 x i8]* %1, i32 0, i32 %in 290*23dcd6e0SJan Vesely %9 = load i8, i8* %7 291*23dcd6e0SJan Vesely %10 = load i8, i8* %8 292*23dcd6e0SJan Vesely %11 = add i8 %9, %10 293*23dcd6e0SJan Vesely %12 = sext i8 %11 to i32 294*23dcd6e0SJan Vesely store i32 %12, i32 addrspace(1)* %out 295*23dcd6e0SJan Vesely ret void 296*23dcd6e0SJan Vesely} 297*23dcd6e0SJan Vesely 298*23dcd6e0SJan Veselydefine void @char_array_array(i32 addrspace(1)* %out, i32 %index) { 299*23dcd6e0SJan Veselyentry: 300*23dcd6e0SJan Vesely %alloca = alloca [2 x [2 x i8]] 301*23dcd6e0SJan Vesely %gep0 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 0 302*23dcd6e0SJan Vesely %gep1 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 1 303*23dcd6e0SJan Vesely store i8 0, i8* %gep0 304*23dcd6e0SJan Vesely store i8 1, i8* %gep1 305*23dcd6e0SJan Vesely %gep2 = getelementptr [2 x [2 x i8]], [2 x [2 x i8]]* %alloca, i32 0, i32 0, i32 %index 306*23dcd6e0SJan Vesely %load = load i8, i8* %gep2 307*23dcd6e0SJan Vesely %sext = sext i8 %load to i32 308*23dcd6e0SJan Vesely store i32 %sext, i32 addrspace(1)* %out 309*23dcd6e0SJan Vesely ret void 310*23dcd6e0SJan Vesely} 311*23dcd6e0SJan Vesely 312*23dcd6e0SJan Veselydefine void @i32_array_array(i32 addrspace(1)* %out, i32 %index) { 313*23dcd6e0SJan Veselyentry: 314*23dcd6e0SJan Vesely %alloca = alloca [2 x [2 x i32]] 315*23dcd6e0SJan Vesely %gep0 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 0 316*23dcd6e0SJan Vesely %gep1 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 1 317*23dcd6e0SJan Vesely store i32 0, i32* %gep0 318*23dcd6e0SJan Vesely store i32 1, i32* %gep1 319*23dcd6e0SJan Vesely %gep2 = getelementptr [2 x [2 x i32]], [2 x [2 x i32]]* %alloca, i32 0, i32 0, i32 %index 320*23dcd6e0SJan Vesely %load = load i32, i32* %gep2 321*23dcd6e0SJan Vesely store i32 %load, i32 addrspace(1)* %out 322*23dcd6e0SJan Vesely ret void 323*23dcd6e0SJan Vesely} 324*23dcd6e0SJan Vesely 325*23dcd6e0SJan Veselydefine void @i64_array_array(i64 addrspace(1)* %out, i32 %index) { 326*23dcd6e0SJan Veselyentry: 327*23dcd6e0SJan Vesely %alloca = alloca [2 x [2 x i64]] 328*23dcd6e0SJan Vesely %gep0 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 0 329*23dcd6e0SJan Vesely %gep1 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 1 330*23dcd6e0SJan Vesely store i64 0, i64* %gep0 331*23dcd6e0SJan Vesely store i64 1, i64* %gep1 332*23dcd6e0SJan Vesely %gep2 = getelementptr [2 x [2 x i64]], [2 x [2 x i64]]* %alloca, i32 0, i32 0, i32 %index 333*23dcd6e0SJan Vesely %load = load i64, i64* %gep2 334*23dcd6e0SJan Vesely store i64 %load, i64 addrspace(1)* %out 335*23dcd6e0SJan Vesely ret void 336*23dcd6e0SJan Vesely} 337*23dcd6e0SJan Vesely 338*23dcd6e0SJan Vesely%struct.pair32 = type { i32, i32 } 339*23dcd6e0SJan Vesely 340*23dcd6e0SJan Veselydefine void @struct_array_array(i32 addrspace(1)* %out, i32 %index) { 341*23dcd6e0SJan Veselyentry: 342*23dcd6e0SJan Vesely %alloca = alloca [2 x [2 x %struct.pair32]] 343*23dcd6e0SJan Vesely %gep0 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 0, i32 1 344*23dcd6e0SJan Vesely %gep1 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 1, i32 1 345*23dcd6e0SJan Vesely store i32 0, i32* %gep0 346*23dcd6e0SJan Vesely store i32 1, i32* %gep1 347*23dcd6e0SJan Vesely %gep2 = getelementptr [2 x [2 x %struct.pair32]], [2 x [2 x %struct.pair32]]* %alloca, i32 0, i32 0, i32 %index, i32 0 348*23dcd6e0SJan Vesely %load = load i32, i32* %gep2 349*23dcd6e0SJan Vesely store i32 %load, i32 addrspace(1)* %out 350*23dcd6e0SJan Vesely ret void 351*23dcd6e0SJan Vesely} 352*23dcd6e0SJan Vesely 353*23dcd6e0SJan Veselydefine void @struct_pair32_array(i32 addrspace(1)* %out, i32 %index) { 354*23dcd6e0SJan Veselyentry: 355*23dcd6e0SJan Vesely %alloca = alloca [2 x %struct.pair32] 356*23dcd6e0SJan Vesely %gep0 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 0, i32 1 357*23dcd6e0SJan Vesely %gep1 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 1, i32 0 358*23dcd6e0SJan Vesely store i32 0, i32* %gep0 359*23dcd6e0SJan Vesely store i32 1, i32* %gep1 360*23dcd6e0SJan Vesely %gep2 = getelementptr [2 x %struct.pair32], [2 x %struct.pair32]* %alloca, i32 0, i32 %index, i32 0 361*23dcd6e0SJan Vesely %load = load i32, i32* %gep2 362*23dcd6e0SJan Vesely store i32 %load, i32 addrspace(1)* %out 363*23dcd6e0SJan Vesely ret void 364*23dcd6e0SJan Vesely} 365*23dcd6e0SJan Vesely 366*23dcd6e0SJan Veselydefine void @select_private(i32 addrspace(1)* %out, i32 %in) nounwind { 367*23dcd6e0SJan Veselyentry: 368*23dcd6e0SJan Vesely %tmp = alloca [2 x i32] 369*23dcd6e0SJan Vesely %tmp1 = getelementptr [2 x i32], [2 x i32]* %tmp, i32 0, i32 0 370*23dcd6e0SJan Vesely %tmp2 = getelementptr [2 x i32], [2 x i32]* %tmp, i32 0, i32 1 371*23dcd6e0SJan Vesely store i32 0, i32* %tmp1 372*23dcd6e0SJan Vesely store i32 1, i32* %tmp2 373*23dcd6e0SJan Vesely %cmp = icmp eq i32 %in, 0 374*23dcd6e0SJan Vesely %sel = select i1 %cmp, i32* %tmp1, i32* %tmp2 375*23dcd6e0SJan Vesely %load = load i32, i32* %sel 376*23dcd6e0SJan Vesely store i32 %load, i32 addrspace(1)* %out 377*23dcd6e0SJan Vesely ret void 378*23dcd6e0SJan Vesely} 379*23dcd6e0SJan Vesely 380*23dcd6e0SJan Vesely; AMDGPUPromoteAlloca does not know how to handle ptrtoint. When it 381*23dcd6e0SJan Vesely; finds one, it should stop trying to promote. 382*23dcd6e0SJan Vesely 383*23dcd6e0SJan Vesely; FUNC-LABEL: ptrtoint: 384*23dcd6e0SJan Vesely; SI-NOT: ds_write 385*23dcd6e0SJan Vesely; SI: buffer_store_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen 386*23dcd6e0SJan Vesely; SI: buffer_load_dword v{{[0-9]+}}, v{{[0-9]+}}, s[{{[0-9]+:[0-9]+}}], s{{[0-9]+}} offen offset:5 ; 387*23dcd6e0SJan Veselydefine void @ptrtoint(i32 addrspace(1)* %out, i32 %a, i32 %b) { 388*23dcd6e0SJan Vesely %alloca = alloca [16 x i32] 389*23dcd6e0SJan Vesely %tmp0 = getelementptr [16 x i32], [16 x i32]* %alloca, i32 0, i32 %a 390*23dcd6e0SJan Vesely store i32 5, i32* %tmp0 391*23dcd6e0SJan Vesely %tmp1 = ptrtoint [16 x i32]* %alloca to i32 392*23dcd6e0SJan Vesely %tmp2 = add i32 %tmp1, 5 393*23dcd6e0SJan Vesely %tmp3 = inttoptr i32 %tmp2 to i32* 394*23dcd6e0SJan Vesely %tmp4 = getelementptr i32, i32* %tmp3, i32 %b 395*23dcd6e0SJan Vesely %tmp5 = load i32, i32* %tmp4 396*23dcd6e0SJan Vesely store i32 %tmp5, i32 addrspace(1)* %out 397*23dcd6e0SJan Vesely ret void 398*23dcd6e0SJan Vesely} 399*23dcd6e0SJan Vesely 400*23dcd6e0SJan Vesely; HSAOPT: !0 = !{} 401*23dcd6e0SJan Vesely; HSAOPT: !1 = !{i32 0, i32 2048} 402*23dcd6e0SJan Vesely 403*23dcd6e0SJan Vesely; NOHSAOPT: !0 = !{i32 0, i32 2048} 404