2017-08-08 02:30:35 +08:00
|
|
|
; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=tahiti -verify-machineinstrs < %s | FileCheck -check-prefix=SI -check-prefix=FUNC %s
|
2018-05-01 03:08:16 +08:00
|
|
|
; RUN: llc -amdgpu-scalarize-global-loads=false -march=amdgcn -mcpu=gfx906 -verify-machineinstrs < %s | FileCheck -check-prefix=GFX906 -check-prefix=FUNC %s
|
2017-12-05 07:07:28 +08:00
|
|
|
; RUN: llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=cypress -verify-machineinstrs < %s | FileCheck -check-prefix=EG -check-prefix=FUNC %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=cedar -verify-machineinstrs < %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=juniper -verify-machineinstrs < %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=redwood -verify-machineinstrs < %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=sumo -verify-machineinstrs < %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=barts -verify-machineinstrs < %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=caicos -verify-machineinstrs < %s
|
|
|
|
; RUN: not llc -amdgpu-scalarize-global-loads=false -march=r600 -mcpu=turks -verify-machineinstrs < %s
|
2013-08-10 18:38:47 +08:00
|
|
|
|
2014-06-26 09:28:05 +08:00
|
|
|
declare float @llvm.fma.f32(float, float, float) nounwind readnone
|
|
|
|
declare <2 x float> @llvm.fma.v2f32(<2 x float>, <2 x float>, <2 x float>) nounwind readnone
|
|
|
|
declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>) nounwind readnone
|
2013-08-10 18:38:47 +08:00
|
|
|
|
2014-11-14 03:26:47 +08:00
|
|
|
declare i32 @llvm.r600.read.tidig.x() nounwind readnone
|
|
|
|
|
2014-10-02 01:15:17 +08:00
|
|
|
; FUNC-LABEL: {{^}}fma_f32:
|
2014-11-05 22:50:53 +08:00
|
|
|
; SI: v_fma_f32 {{v[0-9]+, v[0-9]+, v[0-9]+, v[0-9]+}}
|
2018-05-01 03:08:16 +08:00
|
|
|
; GFX906: v_fmac_f32_e32 {{v[0-9]+, v[0-9]+, v[0-9]+}}
|
2014-10-17 22:45:27 +08:00
|
|
|
|
|
|
|
; EG: MEM_RAT_{{.*}} STORE_{{.*}} [[RES:T[0-9]\.[XYZW]]], {{T[0-9]\.[XYZW]}},
|
|
|
|
; EG: FMA {{\*? *}}[[RES]]
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @fma_f32(float addrspace(1)* %out, float addrspace(1)* %in1,
|
2013-08-10 18:38:47 +08:00
|
|
|
float addrspace(1)* %in2, float addrspace(1)* %in3) {
|
2015-02-28 05:17:42 +08:00
|
|
|
%r0 = load float, float addrspace(1)* %in1
|
|
|
|
%r1 = load float, float addrspace(1)* %in2
|
|
|
|
%r2 = load float, float addrspace(1)* %in3
|
2014-11-14 03:26:47 +08:00
|
|
|
%r3 = tail call float @llvm.fma.f32(float %r0, float %r1, float %r2)
|
|
|
|
store float %r3, float addrspace(1)* %out
|
|
|
|
ret void
|
2013-08-10 18:38:47 +08:00
|
|
|
}
|
|
|
|
|
2018-05-01 03:08:16 +08:00
|
|
|
; GCN-LABEL: {{^}}fmac_to_3addr_f32:
|
|
|
|
; GCN: v_fma_f32 {{v[0-9]+, v[0-9]+, v[0-9]+, v[0-9]+}}
|
|
|
|
define float @fmac_to_3addr_f32(float %r0, float %r1, float %r2) {
|
|
|
|
%r3 = tail call float @llvm.fma.f32(float %r0, float %r1, float %r2)
|
|
|
|
ret float %r3
|
|
|
|
}
|
|
|
|
|
2014-10-02 01:15:17 +08:00
|
|
|
; FUNC-LABEL: {{^}}fma_v2f32:
|
2014-11-05 22:50:53 +08:00
|
|
|
; SI: v_fma_f32
|
|
|
|
; SI: v_fma_f32
|
2014-10-17 22:45:27 +08:00
|
|
|
|
2018-05-01 03:08:16 +08:00
|
|
|
; GFX906: v_fma_f32 {{v[0-9]+, v[0-9]+, v[0-9]+, v[0-9]+}}
|
|
|
|
; GFX906: v_fmac_f32_e32 {{v[0-9]+, v[0-9]+, v[0-9]+}}
|
|
|
|
|
2014-10-17 22:45:27 +08:00
|
|
|
; EG: MEM_RAT_{{.*}} STORE_{{.*}} [[RES:T[0-9]]].[[CHLO:[XYZW]]][[CHHI:[XYZW]]], {{T[0-9]\.[XYZW]}},
|
|
|
|
; EG-DAG: FMA {{\*? *}}[[RES]].[[CHLO]]
|
|
|
|
; EG-DAG: FMA {{\*? *}}[[RES]].[[CHHI]]
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @fma_v2f32(<2 x float> addrspace(1)* %out, <2 x float> addrspace(1)* %in1,
|
2014-06-26 09:28:05 +08:00
|
|
|
<2 x float> addrspace(1)* %in2, <2 x float> addrspace(1)* %in3) {
|
2015-02-28 05:17:42 +08:00
|
|
|
%r0 = load <2 x float>, <2 x float> addrspace(1)* %in1
|
|
|
|
%r1 = load <2 x float>, <2 x float> addrspace(1)* %in2
|
|
|
|
%r2 = load <2 x float>, <2 x float> addrspace(1)* %in3
|
2014-11-14 03:26:47 +08:00
|
|
|
%r3 = tail call <2 x float> @llvm.fma.v2f32(<2 x float> %r0, <2 x float> %r1, <2 x float> %r2)
|
|
|
|
store <2 x float> %r3, <2 x float> addrspace(1)* %out
|
|
|
|
ret void
|
2014-06-26 09:28:05 +08:00
|
|
|
}
|
2013-08-10 18:38:47 +08:00
|
|
|
|
2014-10-02 01:15:17 +08:00
|
|
|
; FUNC-LABEL: {{^}}fma_v4f32:
|
2014-11-05 22:50:53 +08:00
|
|
|
; SI: v_fma_f32
|
|
|
|
; SI: v_fma_f32
|
|
|
|
; SI: v_fma_f32
|
|
|
|
; SI: v_fma_f32
|
2018-05-01 03:08:16 +08:00
|
|
|
; GFX906: v_fma_f32 {{v[0-9]+, v[0-9]+, v[0-9]+, v[0-9]+}}
|
|
|
|
; GFX906: v_fma_f32 {{v[0-9]+, v[0-9]+, v[0-9]+, v[0-9]+}}
|
|
|
|
; GFX906: v_fma_f32 {{v[0-9]+, v[0-9]+, v[0-9]+, v[0-9]+}}
|
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
|
|
|
; GFX906: v_fmac_f32_e32 {{v[0-9]+, v[0-9]+, v[0-9]+$}}
|
2014-10-17 22:45:27 +08:00
|
|
|
|
|
|
|
; EG: MEM_RAT_{{.*}} STORE_{{.*}} [[RES:T[0-9]]].{{[XYZW][XYZW][XYZW][XYZW]}}, {{T[0-9]\.[XYZW]}},
|
|
|
|
; EG-DAG: FMA {{\*? *}}[[RES]].X
|
|
|
|
; EG-DAG: FMA {{\*? *}}[[RES]].Y
|
|
|
|
; EG-DAG: FMA {{\*? *}}[[RES]].Z
|
|
|
|
; EG-DAG: FMA {{\*? *}}[[RES]].W
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @fma_v4f32(<4 x float> addrspace(1)* %out, <4 x float> addrspace(1)* %in1,
|
2014-06-26 09:28:05 +08:00
|
|
|
<4 x float> addrspace(1)* %in2, <4 x float> addrspace(1)* %in3) {
|
2015-02-28 05:17:42 +08:00
|
|
|
%r0 = load <4 x float>, <4 x float> addrspace(1)* %in1
|
|
|
|
%r1 = load <4 x float>, <4 x float> addrspace(1)* %in2
|
|
|
|
%r2 = load <4 x float>, <4 x float> addrspace(1)* %in3
|
2014-11-14 03:26:47 +08:00
|
|
|
%r3 = tail call <4 x float> @llvm.fma.v4f32(<4 x float> %r0, <4 x float> %r1, <4 x float> %r2)
|
|
|
|
store <4 x float> %r3, <4 x float> addrspace(1)* %out
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: @fma_commute_mul_inline_imm_f32
|
2016-04-15 05:58:24 +08:00
|
|
|
; SI: v_fma_f32 {{v[0-9]+}}, {{v[0-9]+}}, 2.0, {{v[0-9]+}}
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @fma_commute_mul_inline_imm_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float addrspace(1)* noalias %in.b) nounwind {
|
2014-11-14 03:26:47 +08:00
|
|
|
%tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
%in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
|
|
|
|
%in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
|
|
|
|
%out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
|
2014-11-14 03:26:47 +08:00
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%a = load float, float addrspace(1)* %in.a.gep, align 4
|
|
|
|
%b = load float, float addrspace(1)* %in.b.gep, align 4
|
2014-11-14 03:26:47 +08:00
|
|
|
|
|
|
|
%fma = call float @llvm.fma.f32(float %a, float 2.0, float %b)
|
|
|
|
store float %fma, float addrspace(1)* %out.gep, align 4
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; FUNC-LABEL: @fma_commute_mul_s_f32
|
2017-03-22 05:39:51 +08:00
|
|
|
define amdgpu_kernel void @fma_commute_mul_s_f32(float addrspace(1)* noalias %out, float addrspace(1)* noalias %in.a, float addrspace(1)* noalias %in.b, float %b) nounwind {
|
2014-11-14 03:26:47 +08:00
|
|
|
%tid = tail call i32 @llvm.r600.read.tidig.x() nounwind readnone
|
[opaque pointer type] Add textual IR support for explicit type parameter to getelementptr instruction
One of several parallel first steps to remove the target type of pointers,
replacing them with a single opaque pointer type.
This adds an explicit type parameter to the gep instruction so that when the
first parameter becomes an opaque pointer type, the type to gep through is
still available to the instructions.
* This doesn't modify gep operators, only instructions (operators will be
handled separately)
* Textual IR changes only. Bitcode (including upgrade) and changing the
in-memory representation will be in separate changes.
* geps of vectors are transformed as:
getelementptr <4 x float*> %x, ...
->getelementptr float, <4 x float*> %x, ...
Then, once the opaque pointer type is introduced, this will ultimately look
like:
getelementptr float, <4 x ptr> %x
with the unambiguous interpretation that it is a vector of pointers to float.
* address spaces remain on the pointer, not the type:
getelementptr float addrspace(1)* %x
->getelementptr float, float addrspace(1)* %x
Then, eventually:
getelementptr float, ptr addrspace(1) %x
Importantly, the massive amount of test case churn has been automated by
same crappy python code. I had to manually update a few test cases that
wouldn't fit the script's model (r228970,r229196,r229197,r229198). The
python script just massages stdin and writes the result to stdout, I
then wrapped that in a shell script to handle replacing files, then
using the usual find+xargs to migrate all the files.
update.py:
import fileinput
import sys
import re
ibrep = re.compile(r"(^.*?[^%\w]getelementptr inbounds )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
normrep = re.compile( r"(^.*?[^%\w]getelementptr )(((?:<\d* x )?)(.*?)(| addrspace\(\d\)) *\*(|>)(?:$| *(?:%|@|null|undef|blockaddress|getelementptr|addrspacecast|bitcast|inttoptr|\[\[[a-zA-Z]|\{\{).*$))")
def conv(match, line):
if not match:
return line
line = match.groups()[0]
if len(match.groups()[5]) == 0:
line += match.groups()[2]
line += match.groups()[3]
line += ", "
line += match.groups()[1]
line += "\n"
return line
for line in sys.stdin:
if line.find("getelementptr ") == line.find("getelementptr inbounds"):
if line.find("getelementptr inbounds") != line.find("getelementptr inbounds ("):
line = conv(re.match(ibrep, line), line)
elif line.find("getelementptr ") != line.find("getelementptr ("):
line = conv(re.match(normrep, line), line)
sys.stdout.write(line)
apply.sh:
for name in "$@"
do
python3 `dirname "$0"`/update.py < "$name" > "$name.tmp" && mv "$name.tmp" "$name"
rm -f "$name.tmp"
done
The actual commands:
From llvm/src:
find test/ -name *.ll | xargs ./apply.sh
From llvm/src/tools/clang:
find test/ -name *.mm -o -name *.m -o -name *.cpp -o -name *.c | xargs -I '{}' ../../apply.sh "{}"
From llvm/src/tools/polly:
find test/ -name *.ll | xargs ./apply.sh
After that, check-all (with llvm, clang, clang-tools-extra, lld,
compiler-rt, and polly all checked out).
The extra 'rm' in the apply.sh script is due to a few files in clang's test
suite using interesting unicode stuff that my python script was throwing
exceptions on. None of those files needed to be migrated, so it seemed
sufficient to ignore those cases.
Reviewers: rafael, dexonsmith, grosser
Differential Revision: http://reviews.llvm.org/D7636
llvm-svn: 230786
2015-02-28 03:29:02 +08:00
|
|
|
%in.a.gep = getelementptr float, float addrspace(1)* %in.a, i32 %tid
|
|
|
|
%in.b.gep = getelementptr float, float addrspace(1)* %in.b, i32 %tid
|
|
|
|
%out.gep = getelementptr float, float addrspace(1)* %out, i32 %tid
|
2014-11-14 03:26:47 +08:00
|
|
|
|
2015-02-28 05:17:42 +08:00
|
|
|
%a = load float, float addrspace(1)* %in.a.gep, align 4
|
|
|
|
%c = load float, float addrspace(1)* %in.b.gep, align 4
|
2014-11-14 03:26:47 +08:00
|
|
|
|
|
|
|
%fma = call float @llvm.fma.f32(float %a, float %b, float %c)
|
|
|
|
store float %fma, float addrspace(1)* %out.gep, align 4
|
|
|
|
ret void
|
2014-06-26 09:28:05 +08:00
|
|
|
}
|
2018-05-01 03:08:16 +08:00
|
|
|
|
|
|
|
; Without special casing the inline constant check for v_fmac_f32's
|
|
|
|
; src2, this fails to fold the 1.0 into an fma.
|
|
|
|
|
|
|
|
; FUNC-LABEL: {{^}}fold_inline_imm_into_fmac_src2_f32:
|
|
|
|
; GFX906: {{buffer|flat|global}}_load_dword [[A:v[0-9]+]]
|
|
|
|
; GFX906: {{buffer|flat|global}}_load_dword [[B:v[0-9]+]]
|
|
|
|
|
|
|
|
; GFX906: v_add_f32_e32 [[TMP2:v[0-9]+]], [[A]], [[A]]
|
|
|
|
; GFX906: v_fma_f32 v{{[0-9]+}}, [[TMP2]], -4.0, 1.0
|
|
|
|
define amdgpu_kernel void @fold_inline_imm_into_fmac_src2_f32(float addrspace(1)* %out, float addrspace(1)* %a, float addrspace(1)* %b) nounwind {
|
|
|
|
bb:
|
|
|
|
%tid = call i32 @llvm.r600.read.tidig.x()
|
|
|
|
%tid.ext = sext i32 %tid to i64
|
|
|
|
%gep.a = getelementptr inbounds float, float addrspace(1)* %a, i64 %tid.ext
|
|
|
|
%gep.b = getelementptr inbounds float, float addrspace(1)* %b, i64 %tid.ext
|
|
|
|
%gep.out = getelementptr inbounds float, float addrspace(1)* %out, i64 %tid.ext
|
|
|
|
%tmp = load volatile float, float addrspace(1)* %gep.a
|
|
|
|
%tmp1 = load volatile float, float addrspace(1)* %gep.b
|
|
|
|
%tmp2 = fadd contract float %tmp, %tmp
|
|
|
|
%tmp3 = fmul contract float %tmp2, 4.0
|
|
|
|
%tmp4 = fsub contract float 1.0, %tmp3
|
|
|
|
%tmp5 = fadd contract float %tmp4, %tmp1
|
|
|
|
%tmp6 = fadd contract float %tmp1, %tmp1
|
|
|
|
%tmp7 = fmul contract float %tmp6, %tmp
|
|
|
|
%tmp8 = fsub contract float 1.0, %tmp7
|
|
|
|
%tmp9 = fmul contract float %tmp8, 8.0
|
|
|
|
%tmp10 = fadd contract float %tmp5, %tmp9
|
|
|
|
store float %tmp10, float addrspace(1)* %gep.out
|
|
|
|
ret void
|
|
|
|
}
|