mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
2b0231f519
This replaces most argument uses with loads, but for now not all. The code in SelectionDAG for calling convention lowering is actively harmful for amdgpu_kernel. It attempts to split the argument types into register legal types, which results in low quality code for arbitary types. Since all kernel arguments are passed in memory, we just want the raw types. I've tried a couple of methods of mitigating this in SelectionDAG, but it's easier to just bypass this problem alltogether. It's possible to hack around the problem in the initial lowering, but the real problem is the DAG then expects to be able to use CopyToReg/CopyFromReg for uses of the arguments outside the block. Exposing the argument loads in the IR also has the advantage that the LoadStoreVectorizer can merge them. I'm not sure the best approach to dealing with the IR argument list is. The patch as-is just leaves the IR arguments in place, so all the existing code will still compute the same kernarg size and pointlessly lowers the arguments. Arguably the frontend should emit kernels with an empty argument list in the first place. Alternatively a dummy array could be inserted as a single argument just to reserve space. This does have some disadvantages. Local pointer kernel arguments can no longer have AssertZext placed on them as the equivalent !range metadata is not valid on pointer typed loads. This is mostly bad for SI which needs to know about the known bits in order to use the DS instruction offset, so in this case this is not done. More importantly, this skips noalias arguments since this pass does not yet convert this to the equivalent !alias.scope and !noalias metadata. Producing this metadata correctly seems to be tricky, although this logically is the same as inlining into a function which doesn't exist. Additionally, exposing these loads to the vectorizer may result in degraded aliasing information if a pointer load is merged with another argument load. I'm also not entirely sure this is preserving the current clover ABI, although I would greatly prefer if it would stop widening arguments and match the HSA ABI. As-is I think it is extending < 4-byte arguments to 4-bytes but doesn't align them to 4-bytes. llvm-svn: 335650
85 lines
3.0 KiB
LLVM
85 lines
3.0 KiB
LLVM
; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -check-prefix=SI %s
|
|
|
|
|
|
declare i32 @llvm.amdgcn.workitem.id.x() readnone
|
|
|
|
; SI-LABEL: {{^}}test_i64_vreg:
|
|
; SI: v_add_i32
|
|
; SI: v_addc_u32
|
|
define amdgpu_kernel void @test_i64_vreg(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %inA, i64 addrspace(1)* noalias %inB) {
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
|
|
%a_ptr = getelementptr i64, i64 addrspace(1)* %inA, i32 %tid
|
|
%b_ptr = getelementptr i64, i64 addrspace(1)* %inB, i32 %tid
|
|
%a = load i64, i64 addrspace(1)* %a_ptr
|
|
%b = load i64, i64 addrspace(1)* %b_ptr
|
|
%result = add i64 %a, %b
|
|
store i64 %result, i64 addrspace(1)* %out
|
|
ret void
|
|
}
|
|
|
|
; Check that the SGPR add operand is correctly moved to a VGPR.
|
|
; SI-LABEL: {{^}}sgpr_operand:
|
|
; SI: s_add_u32
|
|
; SI: s_addc_u32
|
|
define amdgpu_kernel void @sgpr_operand(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in, i64 addrspace(1)* noalias %in_bar, i64 %a) {
|
|
%foo = load i64, i64 addrspace(1)* %in, align 8
|
|
%result = add i64 %foo, %a
|
|
store i64 %result, i64 addrspace(1)* %out
|
|
ret void
|
|
}
|
|
|
|
; Swap the arguments. Check that the SGPR -> VGPR copy works with the
|
|
; SGPR as other operand.
|
|
;
|
|
; SI-LABEL: {{^}}sgpr_operand_reversed:
|
|
; SI: s_add_u32
|
|
; SI: s_addc_u32
|
|
define amdgpu_kernel void @sgpr_operand_reversed(i64 addrspace(1)* noalias %out, i64 addrspace(1)* noalias %in, i64 %a) {
|
|
%foo = load i64, i64 addrspace(1)* %in, align 8
|
|
%result = add i64 %a, %foo
|
|
store i64 %result, i64 addrspace(1)* %out
|
|
ret void
|
|
}
|
|
|
|
|
|
; SI-LABEL: {{^}}test_v2i64_sreg:
|
|
; SI: s_add_u32
|
|
; SI: s_addc_u32
|
|
; SI: s_add_u32
|
|
; SI: s_addc_u32
|
|
define amdgpu_kernel void @test_v2i64_sreg(<2 x i64> addrspace(1)* noalias %out, <2 x i64> %a, <2 x i64> %b) {
|
|
%result = add <2 x i64> %a, %b
|
|
store <2 x i64> %result, <2 x i64> addrspace(1)* %out
|
|
ret void
|
|
}
|
|
|
|
; SI-LABEL: {{^}}test_v2i64_vreg:
|
|
; SI: v_add_i32
|
|
; SI: v_addc_u32
|
|
; SI: v_add_i32
|
|
; SI: v_addc_u32
|
|
define amdgpu_kernel void @test_v2i64_vreg(<2 x i64> addrspace(1)* noalias %out, <2 x i64> addrspace(1)* noalias %inA, <2 x i64> addrspace(1)* noalias %inB) {
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x() readnone
|
|
%a_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %inA, i32 %tid
|
|
%b_ptr = getelementptr <2 x i64>, <2 x i64> addrspace(1)* %inB, i32 %tid
|
|
%a = load <2 x i64>, <2 x i64> addrspace(1)* %a_ptr
|
|
%b = load <2 x i64>, <2 x i64> addrspace(1)* %b_ptr
|
|
%result = add <2 x i64> %a, %b
|
|
store <2 x i64> %result, <2 x i64> addrspace(1)* %out
|
|
ret void
|
|
}
|
|
|
|
; SI-LABEL: {{^}}trunc_i64_add_to_i32:
|
|
; SI: s_load_dword s[[SREG0:[0-9]+]]
|
|
; SI: s_load_dword s[[SREG1:[0-9]+]]
|
|
; SI: s_add_i32 [[SRESULT:s[0-9]+]], s[[SREG1]], s[[SREG0]]
|
|
; SI-NOT: addc
|
|
; SI: v_mov_b32_e32 [[VRESULT:v[0-9]+]], [[SRESULT]]
|
|
; SI: buffer_store_dword [[VRESULT]],
|
|
define amdgpu_kernel void @trunc_i64_add_to_i32(i32 addrspace(1)* %out, i32, i64 %a, i32, i64 %b) {
|
|
%add = add i64 %b, %a
|
|
%trunc = trunc i64 %add to i32
|
|
store i32 %trunc, i32 addrspace(1)* %out, align 8
|
|
ret void
|
|
}
|