2014-09-11 01:58:16 +08:00
|
|
|
; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S | FileCheck %s
|
2012-11-09 15:09:44 +08:00
|
|
|
|
|
|
|
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
|
|
|
|
|
|
|
|
; Make sure we vectorize this loop:
|
|
|
|
; int foo(float *a, float *b, int n) {
|
|
|
|
; for (int i=0; i<n; ++i)
|
|
|
|
; a[i] = b[i] * 3;
|
|
|
|
; }
|
|
|
|
|
2015-07-02 06:18:30 +08:00
|
|
|
;CHECK-LABEL: define i32 @foo
|
2013-01-19 21:57:58 +08:00
|
|
|
;CHECK: for.body.preheader:
|
2015-09-02 18:15:39 +08:00
|
|
|
;CHECK: br i1 %cmp.zero, label %scalar.ph, label %vector.memcheck, !dbg [[BODY_LOC:![0-9]+]]
|
2013-01-19 21:57:58 +08:00
|
|
|
;CHECK: vector.memcheck:
|
2015-09-02 18:15:39 +08:00
|
|
|
;CHECK: br i1 %memcheck.conflict, label %scalar.ph, label %vector.ph, !dbg [[BODY_LOC]]
|
2012-11-09 15:09:44 +08:00
|
|
|
;CHECK: load <4 x float>
|
|
|
|
define i32 @foo(float* nocapture %a, float* nocapture %b, i32 %n) nounwind uwtable ssp {
|
|
|
|
entry:
|
2015-07-02 06:18:30 +08:00
|
|
|
%cmp6 = icmp sgt i32 %n, 0, !dbg !6
|
|
|
|
br i1 %cmp6, label %for.body, label %for.end, !dbg !6
|
2012-11-09 15:09:44 +08:00
|
|
|
|
|
|
|
for.body: ; preds = %entry, %for.body
|
2015-07-02 06:18:30 +08:00
|
|
|
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ], !dbg !7
|
|
|
|
%arrayidx = getelementptr inbounds float, float* %b, i64 %indvars.iv, !dbg !7
|
|
|
|
%0 = load float, float* %arrayidx, align 4, !dbg !7
|
|
|
|
%mul = fmul float %0, 3.000000e+00, !dbg !7
|
|
|
|
%arrayidx2 = getelementptr inbounds float, float* %a, i64 %indvars.iv, !dbg !7
|
|
|
|
store float %mul, float* %arrayidx2, align 4, !dbg !7
|
|
|
|
%indvars.iv.next = add i64 %indvars.iv, 1, !dbg !7
|
|
|
|
%lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !7
|
|
|
|
%exitcond = icmp eq i32 %lftr.wideiv, %n, !dbg !7
|
|
|
|
br i1 %exitcond, label %for.end, label %for.body, !dbg !7
|
2012-11-09 15:09:44 +08:00
|
|
|
|
|
|
|
for.end: ; preds = %for.body, %entry
|
2015-07-02 06:18:30 +08:00
|
|
|
ret i32 undef, !dbg !8
|
2012-11-09 15:09:44 +08:00
|
|
|
}
|
2013-11-01 11:05:07 +08:00
|
|
|
|
|
|
|
; Make sure that we try to vectorize loops with a runtime check if the
|
|
|
|
; dependency check fails.
|
|
|
|
|
|
|
|
; CHECK-LABEL: test_runtime_check
|
|
|
|
; CHECK: <4 x float>
|
|
|
|
define void @test_runtime_check(float* %a, float %b, i64 %offset, i64 %offset2, i64 %n) {
|
|
|
|
entry:
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
for.body:
|
|
|
|
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
|
|
|
|
%ind.sum = add i64 %iv, %offset
|
[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
|
|
|
%arr.idx = getelementptr inbounds float, float* %a, i64 %ind.sum
|
2015-02-28 05:17:42 +08:00
|
|
|
%l1 = load float, float* %arr.idx, align 4
|
2013-11-01 11:05:07 +08:00
|
|
|
%ind.sum2 = add i64 %iv, %offset2
|
[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
|
|
|
%arr.idx2 = getelementptr inbounds float, float* %a, i64 %ind.sum2
|
2015-02-28 05:17:42 +08:00
|
|
|
%l2 = load float, float* %arr.idx2, align 4
|
2013-11-01 11:05:07 +08:00
|
|
|
%m = fmul fast float %b, %l2
|
|
|
|
%ad = fadd fast float %l1, %m
|
|
|
|
store float %ad, float* %arr.idx, align 4
|
|
|
|
%iv.next = add nuw nsw i64 %iv, 1
|
|
|
|
%exitcond = icmp eq i64 %iv.next, %n
|
|
|
|
br i1 %exitcond, label %loopexit, label %for.body
|
|
|
|
|
|
|
|
loopexit:
|
|
|
|
ret void
|
|
|
|
}
|
2015-07-02 06:18:30 +08:00
|
|
|
|
|
|
|
; CHECK: [[BODY_LOC]] = !DILocation(line: 101, column: 1, scope: !{{.*}})
|
|
|
|
|
|
|
|
!llvm.module.flags = !{!0, !1}
|
2016-04-06 07:37:08 +08:00
|
|
|
!llvm.dbg.cu = !{!9}
|
2015-07-02 06:18:30 +08:00
|
|
|
!0 = !{i32 2, !"Dwarf Version", i32 4}
|
|
|
|
!1 = !{i32 2, !"Debug Info Version", i32 3}
|
|
|
|
|
|
|
|
!2 = !{}
|
|
|
|
!3 = !DISubroutineType(types: !2)
|
|
|
|
!4 = !DIFile(filename: "test.cpp", directory: "/tmp")
|
2016-04-15 23:57:41 +08:00
|
|
|
!5 = distinct !DISubprogram(name: "foo", scope: !4, file: !4, line: 99, type: !3, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, unit: !9, variables: !2)
|
2015-07-02 06:18:30 +08:00
|
|
|
!6 = !DILocation(line: 100, column: 1, scope: !5)
|
|
|
|
!7 = !DILocation(line: 101, column: 1, scope: !5)
|
|
|
|
!8 = !DILocation(line: 102, column: 1, scope: !5)
|
2016-04-06 07:37:08 +08:00
|
|
|
!9 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
|
|
|
|
file: !10,
|
|
|
|
isOptimized: true, flags: "-O2",
|
2016-04-15 23:57:41 +08:00
|
|
|
splitDebugFilename: "abc.debug", emissionKind: 2)
|
2016-04-06 07:37:08 +08:00
|
|
|
!10 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
|
|
|
|
!11 = !{i32 2, !"Debug Info Version", i32 3}
|