2018-07-12 04:25:49 +08:00
|
|
|
; RUN: llc -march=amdgcn -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -enable-var-scope -check-prefixes=GCN,FUNC %s
|
|
|
|
; RUN: llc -march=amdgcn -mcpu=tonga -mattr=-flat-for-global -verify-machineinstrs < %s | FileCheck -allow-deprecated-dag-overlap -enable-var-scope -check-prefixes=GCN,FUNC %s
|
|
|
|
; RUN: llc -march=r600 -mcpu=redwood < %s | FileCheck -allow-deprecated-dag-overlap -enable-var-scope -check-prefixes=R600,FUNC %s
|
2013-04-19 10:11:06 +08:00
|
|
|
|
|
|
|
; BFI_INT Definition pattern from ISA docs
|
|
|
|
; (y & x) | (z & ~x)
|
|
|
|
;
|
2018-02-07 08:21:34 +08:00
|
|
|
; FUNC-LABEL: {{^}}bfi_def:
|
2015-02-04 05:53:27 +08:00
|
|
|
; R600: BFI_INT
|
2018-02-07 08:21:34 +08:00
|
|
|
|
|
|
|
; GCN: v_bfi_b32
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @bfi_def(i32 addrspace(1)* %out, i32 %x, i32 %y, i32 %z) {
|
2013-04-19 10:11:06 +08:00
|
|
|
entry:
|
|
|
|
%0 = xor i32 %x, -1
|
|
|
|
%1 = and i32 %z, %0
|
|
|
|
%2 = and i32 %y, %x
|
|
|
|
%3 = or i32 %1, %2
|
|
|
|
store i32 %3, i32 addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; SHA-256 Ch function
|
|
|
|
; z ^ (x & (y ^ z))
|
2018-02-07 08:21:34 +08:00
|
|
|
; FUNC-LABEL: {{^}}bfi_sha256_ch:
|
2015-02-04 05:53:27 +08:00
|
|
|
; R600: BFI_INT
|
2018-02-07 08:21:34 +08:00
|
|
|
|
|
|
|
; GCN: v_bfi_b32
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @bfi_sha256_ch(i32 addrspace(1)* %out, i32 %x, i32 %y, i32 %z) {
|
2013-04-19 10:11:06 +08:00
|
|
|
entry:
|
|
|
|
%0 = xor i32 %y, %z
|
|
|
|
%1 = and i32 %x, %0
|
|
|
|
%2 = xor i32 %z, %1
|
|
|
|
store i32 %2, i32 addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
2013-05-04 01:21:20 +08:00
|
|
|
|
|
|
|
; SHA-256 Ma function
|
|
|
|
; ((x & z) | (y & (x | z)))
|
2018-02-07 08:21:34 +08:00
|
|
|
; FUNC-LABEL: {{^}}bfi_sha256_ma:
|
2015-02-04 05:53:27 +08:00
|
|
|
; R600: XOR_INT * [[DST:T[0-9]+\.[XYZW]]], KC0[2].Z, KC0[2].W
|
|
|
|
; R600: BFI_INT * {{T[0-9]+\.[XYZW]}}, {{[[DST]]|PV\.[XYZW]}}, KC0[3].X, KC0[2].W
|
2013-05-04 01:21:20 +08:00
|
|
|
|
2018-02-07 08:21:34 +08:00
|
|
|
; GCN: v_xor_b32_e32 [[DST:v[0-9]+]], {{s[0-9]+, v[0-9]+}}
|
|
|
|
; GCN: v_bfi_b32 {{v[0-9]+}}, [[DST]], {{s[0-9]+, v[0-9]+}}
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @bfi_sha256_ma(i32 addrspace(1)* %out, i32 %x, i32 %y, i32 %z) {
|
2013-05-04 01:21:20 +08:00
|
|
|
entry:
|
|
|
|
%0 = and i32 %x, %z
|
|
|
|
%1 = or i32 %x, %z
|
|
|
|
%2 = and i32 %y, %1
|
|
|
|
%3 = or i32 %0, %2
|
|
|
|
store i32 %3, i32 addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
2018-02-07 08:21:34 +08:00
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}v_bitselect_v2i32_pat1:
|
|
|
|
; GCN: s_waitcnt
|
|
|
|
; GCN-NEXT: v_bfi_b32 v0, v2, v0, v4
|
2018-08-01 03:05:14 +08:00
|
|
|
; GCN-NEXT: v_bfi_b32 v1, v3, v1, v5
|
2018-02-07 08:21:34 +08:00
|
|
|
; GCN-NEXT: s_setpc_b64
|
|
|
|
define <2 x i32> @v_bitselect_v2i32_pat1(<2 x i32> %a, <2 x i32> %b, <2 x i32> %mask) {
|
|
|
|
%xor.0 = xor <2 x i32> %a, %mask
|
|
|
|
%and = and <2 x i32> %xor.0, %b
|
|
|
|
%bitselect = xor <2 x i32> %and, %mask
|
|
|
|
ret <2 x i32> %bitselect
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}v_bitselect_i64_pat_0:
|
|
|
|
; GCN: s_waitcnt
|
|
|
|
; GCN-NEXT: v_bfi_b32 v1, v1, v3, v5
|
|
|
|
; GCN-NEXT: v_bfi_b32 v0, v0, v2, v4
|
|
|
|
; GCN-NEXT: s_setpc_b64
|
|
|
|
define i64 @v_bitselect_i64_pat_0(i64 %a, i64 %b, i64 %mask) {
|
|
|
|
%and0 = and i64 %a, %b
|
|
|
|
%not.a = xor i64 %a, -1
|
|
|
|
%and1 = and i64 %not.a, %mask
|
|
|
|
%bitselect = or i64 %and0, %and1
|
|
|
|
ret i64 %bitselect
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}v_bitselect_i64_pat_1:
|
|
|
|
; GCN: s_waitcnt
|
|
|
|
; GCN-NEXT: v_bfi_b32 v1, v3, v1, v5
|
|
|
|
; GCN-NEXT: v_bfi_b32 v0, v2, v0, v4
|
|
|
|
; GCN-NEXT: s_setpc_b64
|
|
|
|
define i64 @v_bitselect_i64_pat_1(i64 %a, i64 %b, i64 %mask) {
|
|
|
|
%xor.0 = xor i64 %a, %mask
|
|
|
|
%and = and i64 %xor.0, %b
|
|
|
|
%bitselect = xor i64 %and, %mask
|
|
|
|
ret i64 %bitselect
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}v_bitselect_i64_pat_2:
|
|
|
|
; GCN: s_waitcnt
|
|
|
|
; GCN-DAG: v_bfi_b32 v0, v2, v0, v4
|
|
|
|
; GCN-DAG: v_bfi_b32 v1, v3, v1, v5
|
|
|
|
; GCN-NEXT: s_setpc_b64
|
|
|
|
define i64 @v_bitselect_i64_pat_2(i64 %a, i64 %b, i64 %mask) {
|
|
|
|
%xor.0 = xor i64 %a, %mask
|
|
|
|
%and = and i64 %xor.0, %b
|
|
|
|
%bitselect = xor i64 %and, %mask
|
|
|
|
ret i64 %bitselect
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}v_bfi_sha256_ma_i64:
|
|
|
|
; GCN-DAG: v_xor_b32_e32 v1, v1, v3
|
|
|
|
; GCN-DAG: v_xor_b32_e32 v0, v0, v2
|
|
|
|
; GCN-DAG: v_bfi_b32 v1, v1, v5, v3
|
|
|
|
; GCN-DAG: v_bfi_b32 v0, v0, v4, v2
|
|
|
|
define i64 @v_bfi_sha256_ma_i64(i64 %x, i64 %y, i64 %z) {
|
|
|
|
entry:
|
|
|
|
%and0 = and i64 %x, %z
|
|
|
|
%or0 = or i64 %x, %z
|
|
|
|
%and1 = and i64 %y, %or0
|
|
|
|
%or1 = or i64 %and0, %and1
|
|
|
|
ret i64 %or1
|
|
|
|
}
|
|
|
|
|
|
|
|
; FIXME: Should leave as 64-bit SALU ops
|
|
|
|
; FUNC-LABEL: {{^}}s_bitselect_i64_pat_0:
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
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
|
|
|
; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_bfi_b32
|
|
|
|
; GCN-DAG: v_bfi_b32
|
2018-02-07 08:21:34 +08:00
|
|
|
define amdgpu_kernel void @s_bitselect_i64_pat_0(i64 %a, i64 %b, i64 %mask) {
|
|
|
|
%and0 = and i64 %a, %b
|
|
|
|
%not.a = xor i64 %a, -1
|
|
|
|
%and1 = and i64 %not.a, %mask
|
|
|
|
%bitselect = or i64 %and0, %and1
|
|
|
|
%scalar.use = add i64 %bitselect, 10
|
|
|
|
store i64 %scalar.use, i64 addrspace(1)* undef
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}s_bitselect_i64_pat_1:
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s
|
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
|
|
|
; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_bfi_b32
|
|
|
|
; GCN-DAG: v_bfi_b32
|
2018-02-07 08:21:34 +08:00
|
|
|
define amdgpu_kernel void @s_bitselect_i64_pat_1(i64 %a, i64 %b, i64 %mask) {
|
|
|
|
%xor.0 = xor i64 %a, %mask
|
|
|
|
%and = and i64 %xor.0, %b
|
|
|
|
%bitselect = xor i64 %and, %mask
|
|
|
|
|
|
|
|
%scalar.use = add i64 %bitselect, 10
|
|
|
|
store i64 %scalar.use, i64 addrspace(1)* undef
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}s_bitselect_i64_pat_2:
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_bfi_b32
|
|
|
|
; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s
|
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
|
|
|
; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_bfi_b32
|
2018-02-07 08:21:34 +08:00
|
|
|
define amdgpu_kernel void @s_bitselect_i64_pat_2(i64 %a, i64 %b, i64 %mask) {
|
|
|
|
%xor.0 = xor i64 %a, %mask
|
|
|
|
%and = and i64 %xor.0, %b
|
|
|
|
%bitselect = xor i64 %and, %mask
|
|
|
|
|
|
|
|
%scalar.use = add i64 %bitselect, 10
|
|
|
|
store i64 %scalar.use, i64 addrspace(1)* undef
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}s_bfi_sha256_ma_i64:
|
|
|
|
; GCN: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_xor_b32
|
|
|
|
; GCN-DAG: v_mov_b32_e32 v{{[0-9]+}}, s
|
|
|
|
; GCN-DAG: v_xor_b32
|
|
|
|
; GCN-DAG: v_bfi_b32
|
|
|
|
; GCN: v_bfi_b32
|
|
|
|
define amdgpu_kernel void @s_bfi_sha256_ma_i64(i64 %x, i64 %y, i64 %z) {
|
|
|
|
entry:
|
|
|
|
%and0 = and i64 %x, %z
|
|
|
|
%or0 = or i64 %x, %z
|
|
|
|
%and1 = and i64 %y, %or0
|
|
|
|
%or1 = or i64 %and0, %and1
|
|
|
|
|
|
|
|
%scalar.use = add i64 %or1, 10
|
|
|
|
store i64 %scalar.use, i64 addrspace(1)* undef
|
|
|
|
ret void
|
|
|
|
}
|