llvm-project/llvm/test/Analysis/Delinearization/multidim_only_ivs_2d_nested.ll

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
3.7 KiB
LLVM
Raw Normal View History

; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
split delinearization pass in 3 steps To compute the dimensions of the array in a unique way, we split the delinearization analysis in three steps: - find parametric terms in all memory access functions - compute the array dimensions from the set of terms - compute the delinearized access functions for each dimension The first step is executed on all the memory access functions such that we gather all the patterns in which an array is accessed. The second step reduces all this information in a unique description of the sizes of the array. The third step is delinearizing each memory access function following the common description of the shape of the array computed in step 2. This rewrite of the delinearization pass also solves a problem we had with the previous implementation: because the previous algorithm was by induction on the structure of the SCEV, it would not correctly recognize the shape of the array when the memory access was not following the nesting of the loops: for example, see polly/test/ScopInfo/multidim_only_ivs_3d_reverse.ll ; void foo(long n, long m, long o, double A[n][m][o]) { ; ; for (long i = 0; i < n; i++) ; for (long j = 0; j < m; j++) ; for (long k = 0; k < o; k++) ; A[i][k][j] = 1.0; Starting with this patch we no longer delinearize access functions that do not contain parameters, for example in test/Analysis/DependenceAnalysis/GCD.ll ;; for (long int i = 0; i < 100; i++) ;; for (long int j = 0; j < 100; j++) { ;; A[2*i - 4*j] = i; ;; *B++ = A[6*i + 8*j]; these accesses will not be delinearized as the upper bound of the loops are constants, and their access functions do not contain SCEVUnknown parameters. llvm-svn: 208232
2014-05-08 02:01:20 +08:00
; XFAIL: *
; We do not recognize anymore variable size arrays.
; extern void bar(long n, long m, double A[n][m]);
;
; void foo(long a, long b) {
; for (long n = 1; n < a; ++n)
; for (long m = 1; m < b; ++m) {
; double A[n][m];
; for (long i = 0; i < n; i++)
; for (long j = 0; j < m; j++)
; A[i][j] = 1.0;
; bar(n, m, A);
; }
; }
; AddRec: {{%vla.us,+,{8,+,8}<%for.cond7.preheader.lr.ph.split.us.us>}<%for.body9.lr.ph.us.us>,+,8}<%for.body9.us.us>
; CHECK: Base offset: %vla.us
; CHECK: ArrayDecl[UnknownSize][{1,+,1}<%for.cond7.preheader.lr.ph.split.us.us>] with elements of sizeof(double) bytes.
; CHECK: ArrayRef[{0,+,1}<nuw><nsw><%for.body9.lr.ph.us.us>][{0,+,1}<nuw><nsw><%for.body9.us.us>]
define void @foo(i64 %a, i64 %b) nounwind uwtable {
entry:
%cmp43 = icmp sgt i64 %a, 1
br i1 %cmp43, label %for.cond1.preheader.lr.ph, label %for.end19
for.cond1.preheader.lr.ph: ; preds = %entry
%cmp224 = icmp sgt i64 %b, 1
br label %for.cond1.preheader
for.cond1.preheader: ; preds = %for.inc17, %for.cond1.preheader.lr.ph
%indvars.iv51 = phi i64 [ 1, %for.cond1.preheader.lr.ph ], [ %indvars.iv.next52, %for.inc17 ]
br i1 %cmp224, label %for.cond7.preheader.lr.ph.split.us.us, label %for.inc17
for.end13.us: ; preds = %for.inc11.us.us
call void @bar(i64 %indvars.iv51, i64 %indvars.iv48, double* %vla.us) nounwind
call void @llvm.stackrestore(i8* %1)
%indvars.iv.next49 = add i64 %indvars.iv48, 1
%exitcond54 = icmp eq i64 %indvars.iv.next49, %b
br i1 %exitcond54, label %for.inc17, label %for.cond7.preheader.lr.ph.split.us.us
for.inc11.us.us: ; preds = %for.body9.us.us
%inc12.us.us = add nsw i64 %i.023.us.us, 1
%exitcond53 = icmp eq i64 %inc12.us.us, %indvars.iv51
br i1 %exitcond53, label %for.end13.us, label %for.body9.lr.ph.us.us
for.body9.lr.ph.us.us: ; preds = %for.cond7.preheader.lr.ph.split.us.us, %for.inc11.us.us
%i.023.us.us = phi i64 [ 0, %for.cond7.preheader.lr.ph.split.us.us ], [ %inc12.us.us, %for.inc11.us.us ]
%0 = mul nsw i64 %i.023.us.us, %indvars.iv48
br label %for.body9.us.us
for.body9.us.us: ; preds = %for.body9.us.us, %for.body9.lr.ph.us.us
%j.021.us.us = phi i64 [ 0, %for.body9.lr.ph.us.us ], [ %inc.us.us, %for.body9.us.us ]
%arrayidx.sum.us.us = add i64 %j.021.us.us, %0
[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
%arrayidx10.us.us = getelementptr inbounds double, double* %vla.us, i64 %arrayidx.sum.us.us
store double 1.000000e+00, double* %arrayidx10.us.us, align 8
%inc.us.us = add nsw i64 %j.021.us.us, 1
%exitcond50 = icmp eq i64 %inc.us.us, %indvars.iv48
br i1 %exitcond50, label %for.inc11.us.us, label %for.body9.us.us
for.cond7.preheader.lr.ph.split.us.us: ; preds = %for.cond1.preheader, %for.end13.us
%indvars.iv48 = phi i64 [ %indvars.iv.next49, %for.end13.us ], [ 1, %for.cond1.preheader ]
%1 = call i8* @llvm.stacksave()
%2 = mul nuw i64 %indvars.iv48, %indvars.iv51
%vla.us = alloca double, i64 %2, align 16
br label %for.body9.lr.ph.us.us
for.inc17: ; preds = %for.end13.us, %for.cond1.preheader
%indvars.iv.next52 = add i64 %indvars.iv51, 1
%exitcond55 = icmp eq i64 %indvars.iv.next52, %a
br i1 %exitcond55, label %for.end19, label %for.cond1.preheader
for.end19: ; preds = %for.inc17, %entry
ret void
}
declare i8* @llvm.stacksave() nounwind
declare void @bar(i64, i64, double*)
declare void @llvm.stackrestore(i8*) nounwind