2018-05-22 14:32:10 +08:00
|
|
|
; RUN: llc -march=amdgcn -mcpu=gfx900 -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,GFX9 %s
|
|
|
|
; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,VI,CIVI %s
|
|
|
|
; RUN: llc -march=amdgcn -mcpu=bonaire -verify-machineinstrs < %s | FileCheck -enable-var-scope -check-prefixes=GCN,CI,CIVI %s
|
2017-02-28 06:15:25 +08:00
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}s_shl_v2i16:
|
|
|
|
; GFX9: s_load_dword [[LHS:s[0-9]+]]
|
|
|
|
; GFX9: s_load_dword [[RHS:s[0-9]+]]
|
|
|
|
; GFX9: v_mov_b32_e32 [[VLHS:v[0-9]+]], [[LHS]]
|
|
|
|
; GFX9: v_pk_lshlrev_b16 [[RESULT:v[0-9]+]], [[RHS]], [[VLHS]]
|
|
|
|
|
2018-05-22 14:32:10 +08:00
|
|
|
; VI: s_load_dword s
|
|
|
|
; VI: s_load_dword s
|
|
|
|
; VI: s_lshr_b32
|
|
|
|
; VI: s_lshr_b32
|
|
|
|
; VI: s_and_b32
|
|
|
|
; VI: s_and_b32
|
AMDGPU: Add pass to lower kernel arguments to loads
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
2018-06-27 03:10:00 +08:00
|
|
|
; VI: s_lshl_b32
|
|
|
|
; VI: s_lshl_b32
|
|
|
|
; VI: s_lshl_b32
|
AMDGPU: Try a lot harder to emit scalar loads
This has two main components. First, widen
widen short constant loads in DAG when they have
the correct alignment. This is already done a bit in
AMDGPUCodeGenPrepare, since that has access to
DivergenceAnalysis. This can't help kernarg loads
created in the DAG. Start to use DAG divergence analysis
to help this case.
The second part is to avoid kernel argument lowering
breaking the alignment of short vector elements because
calling convention lowering wants to split everything
into legal register types.
When loading a split type, load the nearest 4-byte aligned
segment and shift to get the desired bits. This extra
load of the earlier argument piece ends up merging,
and the bit extract hopefully folds out.
There are a number of improvements and regressions with
this, but I think as-is this is a better compromise between
several of the worst parts of SelectionDAG.
Particularly when i16 is legal, this produces worse code
for i8 and i16 element vector kernel arguments. This is
partially due to the very weak load merging the DAG does.
It only looks for fairly specific combines between pairs
of loads which no longer appear. In particular this
causes v4i16 loads to be split into 2 components when
previously the two halves were merged.
Worse, because of the newly introduced shifts, there
is a lot more unnecessary vector packing and unpacking code
emitted. At least some of this is due to reporting
false for isTypeDesirableForOp for i16 as a workaround for
the lack of divergence information in the DAG. The cases
where this happens it doesn't actually matter, but the
relevant code in SimplifyDemandedBits doens't have the context
to know to ignore this.
The use of the scalar cache is probably more important
than the mess of mostly scalar instructions doing this packing
and unpacking. Future work can fix this, possibly by making better
use of the new DAG divergence information for controlling promotion
decisions, or adding another version of shift + trunc + shift
combines that doesn't only know about the used types.
llvm-svn: 334180
2018-06-07 17:54:49 +08:00
|
|
|
; VI: s_and_b32
|
|
|
|
; VI: s_or_b32
|
|
|
|
|
|
|
|
; CI: s_load_dword s
|
|
|
|
; CI: s_load_dword s
|
|
|
|
; CI: s_lshr_b32
|
|
|
|
; CI: s_and_b32
|
|
|
|
; CI: s_lshr_b32
|
|
|
|
; CI: s_lshl_b32
|
|
|
|
; CI: s_lshl_b32
|
|
|
|
; CI: s_lshl_b32
|
|
|
|
; CI: s_and_b32
|
|
|
|
; CI: s_or_b32
|
|
|
|
; CI: _store_dword
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @s_shl_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> %lhs, <2 x i16> %rhs) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%result = shl <2 x i16> %lhs, %rhs
|
|
|
|
store <2 x i16> %result, <2 x i16> addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}v_shl_v2i16:
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_load_dword [[LHS:v[0-9]+]]
|
|
|
|
; GCN: {{buffer|flat|global}}_load_dword [[RHS:v[0-9]+]]
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 [[RESULT:v[0-9]+]], [[RHS]], [[LHS]]
|
|
|
|
|
|
|
|
; VI: v_lshlrev_b16_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
2017-04-06 23:03:28 +08:00
|
|
|
; VI: v_lshlrev_b16_sdwa v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}} dst_sel:WORD_1 dst_unused:UNUSED_PAD src0_sel:WORD_1 src1_sel:WORD_1
|
2017-02-28 06:15:25 +08:00
|
|
|
; VI: v_or_b32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
|
|
|
|
|
|
|
; CI: s_mov_b32 [[MASK:s[0-9]+]], 0xffff{{$}}
|
|
|
|
; CI: v_lshrrev_b32_e32 v{{[0-9]+}}, 16, [[LHS]]
|
|
|
|
; CI: v_lshrrev_b32_e32 v{{[0-9]+}}, 16, v{{[0-9]+}}
|
|
|
|
; CI: v_lshlrev_b32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
|
|
|
; CI: v_lshl_b32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
|
|
|
; CI: v_lshlrev_b32_e32 v{{[0-9]+}}, 16, v{{[0-9]+}}
|
|
|
|
; CI: v_and_b32_e32 v{{[0-9]+}}, [[MASK]], v{{[0-9]+}}
|
|
|
|
; CI: v_or_b32_e32 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @v_shl_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %in) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%b_ptr = getelementptr <2 x i16>, <2 x i16> addrspace(1)* %in.gep, i32 1
|
|
|
|
%a = load <2 x i16>, <2 x i16> addrspace(1)* %in.gep
|
|
|
|
%b = load <2 x i16>, <2 x i16> addrspace(1)* %b_ptr
|
|
|
|
%result = shl <2 x i16> %a, %b
|
|
|
|
store <2 x i16> %result, <2 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}shl_v_s_v2i16:
|
|
|
|
; GFX9: s_load_dword [[RHS:s[0-9]+]]
|
2017-07-29 09:03:53 +08:00
|
|
|
; GFX9: {{buffer|flat|global}}_load_dword [[LHS:v[0-9]+]]
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 [[RESULT:v[0-9]+]], [[RHS]], [[LHS]]
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @shl_v_s_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %in, <2 x i16> %sgpr) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%vgpr = load <2 x i16>, <2 x i16> addrspace(1)* %in.gep
|
|
|
|
%result = shl <2 x i16> %vgpr, %sgpr
|
|
|
|
store <2 x i16> %result, <2 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}shl_s_v_v2i16:
|
|
|
|
; GFX9: s_load_dword [[LHS:s[0-9]+]]
|
2017-07-29 09:03:53 +08:00
|
|
|
; GFX9: {{buffer|flat|global}}_load_dword [[RHS:v[0-9]+]]
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 [[RESULT:v[0-9]+]], [[RHS]], [[LHS]]
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @shl_s_v_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %in, <2 x i16> %sgpr) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%vgpr = load <2 x i16>, <2 x i16> addrspace(1)* %in.gep
|
|
|
|
%result = shl <2 x i16> %sgpr, %vgpr
|
|
|
|
store <2 x i16> %result, <2 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}shl_imm_v_v2i16:
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_load_dword [[RHS:v[0-9]+]]
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 [[RESULT:v[0-9]+]], [[RHS]], 8
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @shl_imm_v_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %in) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%vgpr = load <2 x i16>, <2 x i16> addrspace(1)* %in.gep
|
|
|
|
%result = shl <2 x i16> <i16 8, i16 8>, %vgpr
|
|
|
|
store <2 x i16> %result, <2 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}shl_v_imm_v2i16:
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_load_dword [[LHS:v[0-9]+]]
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 [[RESULT:v[0-9]+]], 8, [[LHS]]
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @shl_v_imm_v2i16(<2 x i16> addrspace(1)* %out, <2 x i16> addrspace(1)* %in) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <2 x i16>, <2 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%vgpr = load <2 x i16>, <2 x i16> addrspace(1)* %in.gep
|
|
|
|
%result = shl <2 x i16> %vgpr, <i16 8, i16 8>
|
|
|
|
store <2 x i16> %result, <2 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}v_shl_v4i16:
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_load_dwordx2
|
|
|
|
; GCN: {{buffer|flat|global}}_load_dwordx2
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
|
|
|
; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, v{{[0-9]+}}, v{{[0-9]+}}
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_store_dwordx2
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @v_shl_v4i16(<4 x i16> addrspace(1)* %out, <4 x i16> addrspace(1)* %in) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <4 x i16>, <4 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <4 x i16>, <4 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%b_ptr = getelementptr <4 x i16>, <4 x i16> addrspace(1)* %in.gep, i32 1
|
|
|
|
%a = load <4 x i16>, <4 x i16> addrspace(1)* %in.gep
|
|
|
|
%b = load <4 x i16>, <4 x i16> addrspace(1)* %b_ptr
|
|
|
|
%result = shl <4 x i16> %a, %b
|
|
|
|
store <4 x i16> %result, <4 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; GCN-LABEL: {{^}}shl_v_imm_v4i16:
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_load_dwordx2
|
2017-02-28 06:15:25 +08:00
|
|
|
; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, 8, v{{[0-9]+}}
|
|
|
|
; GFX9: v_pk_lshlrev_b16 v{{[0-9]+}}, 8, v{{[0-9]+}}
|
2017-07-29 09:03:53 +08:00
|
|
|
; GCN: {{buffer|flat|global}}_store_dwordx2
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @shl_v_imm_v4i16(<4 x i16> addrspace(1)* %out, <4 x i16> addrspace(1)* %in) #0 {
|
2017-02-28 06:15:25 +08:00
|
|
|
%tid = call i32 @llvm.amdgcn.workitem.id.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%in.gep = getelementptr inbounds <4 x i16>, <4 x i16> addrspace(1)* %in, i64 %tid.ext
|
|
|
|
%out.gep = getelementptr inbounds <4 x i16>, <4 x i16> addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%vgpr = load <4 x i16>, <4 x i16> addrspace(1)* %in.gep
|
|
|
|
%result = shl <4 x i16> %vgpr, <i16 8, i16 8, i16 8, i16 8>
|
|
|
|
store <4 x i16> %result, <4 x i16> addrspace(1)* %out.gep
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
declare i32 @llvm.amdgcn.workitem.id.x() #1
|
|
|
|
|
|
|
|
attributes #0 = { nounwind }
|
|
|
|
attributes #1 = { nounwind readnone }
|