2014-04-04 05:18:25 +08:00
|
|
|
; RUN: llc < %s -march=nvptx -mcpu=sm_20 | FileCheck %s --check-prefix PTX
|
|
|
|
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s --check-prefix PTX
|
2017-01-31 09:10:58 +08:00
|
|
|
; RUN: opt -mtriple=nvptx-- < %s -S -infer-address-spaces | FileCheck %s --check-prefix IR
|
|
|
|
; RUN: opt -mtriple=nvptx64-- < %s -S -infer-address-spaces | FileCheck %s --check-prefix IR
|
2014-04-04 05:18:25 +08:00
|
|
|
|
|
|
|
@array = internal addrspace(3) global [10 x float] zeroinitializer, align 4
|
|
|
|
@scalar = internal addrspace(3) global float 0.000000e+00, align 4
|
|
|
|
|
|
|
|
; Verifies nvptx-favor-non-generic correctly optimizes generic address space
|
|
|
|
; usage to non-generic address space usage for the patterns we claim to handle:
|
|
|
|
; 1. load cast
|
|
|
|
; 2. store cast
|
|
|
|
; 3. load gep cast
|
|
|
|
; 4. store gep cast
|
|
|
|
; gep and cast can be an instruction or a constant expression. This function
|
|
|
|
; tries all possible combinations.
|
2016-03-21 04:59:20 +08:00
|
|
|
define void @ld_st_shared_f32(i32 %i, float %v) {
|
2014-04-04 05:18:25 +08:00
|
|
|
; IR-LABEL: @ld_st_shared_f32
|
|
|
|
; IR-NOT: addrspacecast
|
|
|
|
; PTX-LABEL: ld_st_shared_f32(
|
|
|
|
; load cast
|
2015-02-28 05:17:42 +08:00
|
|
|
%1 = load float, float* addrspacecast (float addrspace(3)* @scalar to float*), align 4
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %1)
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: ld.shared.f32 %f{{[0-9]+}}, [scalar];
|
|
|
|
; store cast
|
|
|
|
store float %v, float* addrspacecast (float addrspace(3)* @scalar to float*), align 4
|
|
|
|
; PTX: st.shared.f32 [scalar], %f{{[0-9]+}};
|
|
|
|
; use syncthreads to disable optimizations across components
|
2016-07-07 04:02:45 +08:00
|
|
|
call void @llvm.nvvm.barrier0()
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: bar.sync 0;
|
|
|
|
|
|
|
|
; cast; load
|
|
|
|
%2 = addrspacecast float addrspace(3)* @scalar to float*
|
2015-02-28 05:17:42 +08:00
|
|
|
%3 = load float, float* %2, align 4
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %3)
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: ld.shared.f32 %f{{[0-9]+}}, [scalar];
|
|
|
|
; cast; store
|
|
|
|
store float %v, float* %2, align 4
|
|
|
|
; PTX: st.shared.f32 [scalar], %f{{[0-9]+}};
|
2016-07-07 04:02:45 +08:00
|
|
|
call void @llvm.nvvm.barrier0()
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: bar.sync 0;
|
|
|
|
|
|
|
|
; load gep cast
|
2015-03-14 02:20:45 +08:00
|
|
|
%4 = load float, float* getelementptr inbounds ([10 x float], [10 x float]* addrspacecast ([10 x float] addrspace(3)* @array to [10 x float]*), i32 0, i32 5), align 4
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %4)
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: ld.shared.f32 %f{{[0-9]+}}, [array+20];
|
|
|
|
; store gep cast
|
2015-03-14 02:20:45 +08:00
|
|
|
store float %v, float* getelementptr inbounds ([10 x float], [10 x float]* addrspacecast ([10 x float] addrspace(3)* @array to [10 x float]*), i32 0, i32 5), align 4
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: st.shared.f32 [array+20], %f{{[0-9]+}};
|
2016-07-07 04:02:45 +08:00
|
|
|
call void @llvm.nvvm.barrier0()
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: bar.sync 0;
|
|
|
|
|
|
|
|
; gep cast; load
|
[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
|
|
|
%5 = getelementptr inbounds [10 x float], [10 x float]* addrspacecast ([10 x float] addrspace(3)* @array to [10 x float]*), i32 0, i32 5
|
2015-02-28 05:17:42 +08:00
|
|
|
%6 = load float, float* %5, align 4
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %6)
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: ld.shared.f32 %f{{[0-9]+}}, [array+20];
|
|
|
|
; gep cast; store
|
|
|
|
store float %v, float* %5, align 4
|
|
|
|
; PTX: st.shared.f32 [array+20], %f{{[0-9]+}};
|
2016-07-07 04:02:45 +08:00
|
|
|
call void @llvm.nvvm.barrier0()
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: bar.sync 0;
|
|
|
|
|
|
|
|
; cast; gep; load
|
|
|
|
%7 = addrspacecast [10 x float] addrspace(3)* @array to [10 x float]*
|
[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
|
|
|
%8 = getelementptr inbounds [10 x float], [10 x float]* %7, i32 0, i32 %i
|
2015-02-28 05:17:42 +08:00
|
|
|
%9 = load float, float* %8, align 4
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %9)
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: ld.shared.f32 %f{{[0-9]+}}, [%{{(r|rl|rd)[0-9]+}}];
|
|
|
|
; cast; gep; store
|
|
|
|
store float %v, float* %8, align 4
|
|
|
|
; PTX: st.shared.f32 [%{{(r|rl|rd)[0-9]+}}], %f{{[0-9]+}};
|
2016-07-07 04:02:45 +08:00
|
|
|
call void @llvm.nvvm.barrier0()
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX: bar.sync 0;
|
|
|
|
|
2016-03-21 04:59:20 +08:00
|
|
|
ret void
|
2014-04-04 05:18:25 +08:00
|
|
|
}
|
|
|
|
|
2014-06-16 05:40:57 +08:00
|
|
|
; When hoisting an addrspacecast between different pointer types, replace the
|
|
|
|
; addrspacecast with a bitcast.
|
2014-04-04 05:18:25 +08:00
|
|
|
define i32 @ld_int_from_float() {
|
|
|
|
; IR-LABEL: @ld_int_from_float
|
2015-02-28 05:17:42 +08:00
|
|
|
; IR: load i32, i32 addrspace(3)* bitcast (float addrspace(3)* @scalar to i32 addrspace(3)*)
|
2014-04-04 05:18:25 +08:00
|
|
|
; PTX-LABEL: ld_int_from_float(
|
2014-06-16 05:40:57 +08:00
|
|
|
; PTX: ld.shared.u{{(32|64)}}
|
2015-02-28 05:17:42 +08:00
|
|
|
%1 = load i32, i32* addrspacecast(float addrspace(3)* @scalar to i32*), align 4
|
2014-04-04 05:18:25 +08:00
|
|
|
ret i32 %1
|
|
|
|
}
|
|
|
|
|
2015-05-30 01:00:27 +08:00
|
|
|
define i32 @ld_int_from_global_float(float addrspace(1)* %input, i32 %i, i32 %j) {
|
|
|
|
; IR-LABEL: @ld_int_from_global_float(
|
|
|
|
; PTX-LABEL: ld_int_from_global_float(
|
|
|
|
%1 = addrspacecast float addrspace(1)* %input to float*
|
|
|
|
%2 = getelementptr float, float* %1, i32 %i
|
|
|
|
; IR-NEXT: getelementptr float, float addrspace(1)* %input, i32 %i
|
|
|
|
%3 = getelementptr float, float* %2, i32 %j
|
|
|
|
; IR-NEXT: getelementptr float, float addrspace(1)* {{%[^,]+}}, i32 %j
|
|
|
|
%4 = bitcast float* %3 to i32*
|
|
|
|
; IR-NEXT: bitcast float addrspace(1)* {{%[^ ]+}} to i32 addrspace(1)*
|
|
|
|
%5 = load i32, i32* %4
|
|
|
|
; IR-NEXT: load i32, i32 addrspace(1)* {{%.+}}
|
|
|
|
; PTX-LABEL: ld.global
|
|
|
|
ret i32 %5
|
|
|
|
}
|
|
|
|
|
2015-06-10 05:50:32 +08:00
|
|
|
define void @nested_const_expr() {
|
|
|
|
; PTX-LABEL: nested_const_expr(
|
|
|
|
; store 1 to bitcast(gep(addrspacecast(array), 0, 1))
|
|
|
|
store i32 1, i32* bitcast (float* getelementptr ([10 x float], [10 x float]* addrspacecast ([10 x float] addrspace(3)* @array to [10 x float]*), i64 0, i64 1) to i32*), align 4
|
|
|
|
; PTX: mov.u32 %r1, 1;
|
|
|
|
; PTX-NEXT: st.shared.u32 [array+4], %r1;
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
define void @rauw(float addrspace(1)* %input) {
|
|
|
|
%generic_input = addrspacecast float addrspace(1)* %input to float*
|
|
|
|
%addr = getelementptr float, float* %generic_input, i64 10
|
|
|
|
%v = load float, float* %addr
|
|
|
|
store float %v, float* %addr
|
|
|
|
ret void
|
|
|
|
; IR-LABEL: @rauw(
|
2016-03-21 04:59:20 +08:00
|
|
|
; IR-NEXT: %addr = getelementptr float, float addrspace(1)* %input, i64 10
|
|
|
|
; IR-NEXT: %v = load float, float addrspace(1)* %addr
|
|
|
|
; IR-NEXT: store float %v, float addrspace(1)* %addr
|
2015-06-10 05:50:32 +08:00
|
|
|
; IR-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2016-03-21 04:59:20 +08:00
|
|
|
define void @loop() {
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR-LABEL: @loop(
|
2016-03-21 04:59:20 +08:00
|
|
|
entry:
|
|
|
|
%p = addrspacecast [10 x float] addrspace(3)* @array to float*
|
|
|
|
%end = getelementptr float, float* %p, i64 10
|
|
|
|
br label %loop
|
|
|
|
|
|
|
|
loop:
|
|
|
|
%i = phi float* [ %p, %entry ], [ %i2, %loop ]
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: phi float addrspace(3)* [ %p, %entry ], [ %i2, %loop ]
|
2016-03-21 04:59:20 +08:00
|
|
|
%v = load float, float* %i
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: %v = load float, float addrspace(3)* %i
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %v)
|
|
|
|
%i2 = getelementptr float, float* %i, i64 1
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: %i2 = getelementptr float, float addrspace(3)* %i, i64 1
|
2016-03-21 04:59:20 +08:00
|
|
|
%exit_cond = icmp eq float* %i2, %end
|
|
|
|
br i1 %exit_cond, label %exit, label %loop
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
@generic_end = external global float*
|
|
|
|
|
|
|
|
define void @loop_with_generic_bound() {
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR-LABEL: @loop_with_generic_bound(
|
2016-03-21 04:59:20 +08:00
|
|
|
entry:
|
|
|
|
%p = addrspacecast [10 x float] addrspace(3)* @array to float*
|
|
|
|
%end = load float*, float** @generic_end
|
|
|
|
br label %loop
|
|
|
|
|
|
|
|
loop:
|
|
|
|
%i = phi float* [ %p, %entry ], [ %i2, %loop ]
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: phi float addrspace(3)* [ %p, %entry ], [ %i2, %loop ]
|
2016-03-21 04:59:20 +08:00
|
|
|
%v = load float, float* %i
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: %v = load float, float addrspace(3)* %i
|
2016-03-21 04:59:20 +08:00
|
|
|
call void @use(float %v)
|
|
|
|
%i2 = getelementptr float, float* %i, i64 1
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: %i2 = getelementptr float, float addrspace(3)* %i, i64 1
|
2016-03-21 04:59:20 +08:00
|
|
|
%exit_cond = icmp eq float* %i2, %end
|
2016-11-01 05:51:42 +08:00
|
|
|
; IR: addrspacecast float addrspace(3)* %i2 to float*
|
|
|
|
; IR: icmp eq float* %{{[0-9]+}}, %end
|
2016-03-21 04:59:20 +08:00
|
|
|
br i1 %exit_cond, label %exit, label %loop
|
|
|
|
|
|
|
|
exit:
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2016-07-07 04:02:45 +08:00
|
|
|
declare void @llvm.nvvm.barrier0() #3
|
2014-04-04 05:18:25 +08:00
|
|
|
|
2016-03-21 04:59:20 +08:00
|
|
|
declare void @use(float)
|
2014-04-04 05:18:25 +08:00
|
|
|
|
2016-03-21 04:59:20 +08:00
|
|
|
attributes #3 = { noduplicate nounwind }
|