llvm.org GIT mirror llvm / 4439d65
[SCEV] Assume parameters coming from function calls contain IVs The optimistic delinearization implemented in LLVM detects array sizes by looking for non-linear products between parameters and induction variables. In OpenCL code, such products often look like: A[get_global_id(0) * N + get_global_id(1)] Hence, the IV is hidden in the get_global_id() call and consequently delinearization would fail as no induction variable is available that helps us to identify N as array size parameter. We now use a very simple heuristic to change this. We assume that each parameter that comes directly from a function call is a hidden induction variable. As a result, we can delinearize the access above to: A[get_global_id(0)][get_global_id(1] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@304073 91177308-0d34-0410-b5e6-96231b3b80d8 Tobias Grosser 3 years ago
2 changed file(s) with 84 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
95899589 bool HasAddRec = false;
95909590 SmallVector Operands;
95919591 for (auto Op : Mul->operands()) {
9592 if (isa(Op)) {
9592 const SCEVUnknown *Unknown = dyn_cast(Op);
9593 if (Unknown && !isa(Unknown->getValue())) {
95939594 Operands.push_back(Op);
9595 } else if (Unknown) {
9596 HasAddRec = true;
95949597 } else {
95959598 bool ContainsAddRec;
95969599 SCEVHasAddRec ContiansAddRec(ContainsAddRec);
0 ; RUN: opt -delinearize -analyze < %s | FileCheck %s
1
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3
4 ; CHECK: Inst: %tmp = load float, float* %arrayidx, align 4
5 ; CHECK-NEXT: In Loop with Header: for.inc
6 ; CHECK-NEXT: AccessFunction: {(4 * %N * %call),+,4}<%for.inc>
7 ; CHECK-NEXT: Base offset: %A
8 ; CHECK-NEXT: ArrayDecl[UnknownSize][%N] with elements of 4 bytes.
9 ; CHECK-NEXT: ArrayRef[%call][{0,+,1}<%for.inc>]
10
11 ; CHECK: Inst: %tmp5 = load float, float* %arrayidx4, align 4
12 ; CHECK-NEXT: In Loop with Header: for.inc
13 ; CHECK-NEXT: AccessFunction: {(4 * %call1),+,(4 * %N)}<%for.inc>
14 ; CHECK-NEXT: Base offset: %B
15 ; CHECK-NEXT: ArrayDecl[UnknownSize][%N] with elements of 4 bytes.
16 ; CHECK-NEXT: ArrayRef[{0,+,1}<%for.inc>][%call1]
17
18 ; Function Attrs: noinline nounwind uwtable
19 define void @mat_mul(float* %C, float* %A, float* %B, i64 %N) #0 !kernel_arg_addr_space !2 !kernel_arg_access_qual !3 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !5 {
20 entry:
21 br label %entry.split
22
23 entry.split: ; preds = %entry
24 %call = tail call i64 @_Z13get_global_idj(i32 0) #3
25 %call1 = tail call i64 @_Z13get_global_idj(i32 1) #3
26 %cmp1 = icmp sgt i64 %N, 0
27 %mul = mul nsw i64 %call, %N
28 br i1 %cmp1, label %for.inc.lr.ph, label %for.end
29
30 for.inc.lr.ph: ; preds = %entry.split
31 br label %for.inc
32
33 for.inc: ; preds = %for.inc.lr.ph, %for.inc
34 %acc.03 = phi float [ 0.000000e+00, %for.inc.lr.ph ], [ %tmp6, %for.inc ]
35 %m.02 = phi i64 [ 0, %for.inc.lr.ph ], [ %inc, %for.inc ]
36 %add = add nsw i64 %m.02, %mul
37 %arrayidx = getelementptr inbounds float, float* %A, i64 %add
38 %tmp = load float, float* %arrayidx, align 4
39 %mul2 = mul nsw i64 %m.02, %N
40 %add3 = add nsw i64 %mul2, %call1
41 %arrayidx4 = getelementptr inbounds float, float* %B, i64 %add3
42 %tmp5 = load float, float* %arrayidx4, align 4
43 %tmp6 = tail call float @llvm.fmuladd.f32(float %tmp, float %tmp5, float %acc.03)
44 %inc = add nuw nsw i64 %m.02, 1
45 %exitcond = icmp ne i64 %inc, %N
46 br i1 %exitcond, label %for.inc, label %for.cond.for.end_crit_edge
47
48 for.cond.for.end_crit_edge: ; preds = %for.inc
49 %.lcssa = phi float [ %tmp6, %for.inc ]
50 br label %for.end
51
52 for.end: ; preds = %for.cond.for.end_crit_edge, %entry.split
53 %acc.0.lcssa = phi float [ %.lcssa, %for.cond.for.end_crit_edge ], [ 0.000000e+00, %entry.split ]
54 %add7 = add nsw i64 %mul, %call1
55 %arrayidx8 = getelementptr inbounds float, float* %C, i64 %add7
56 store float %acc.0.lcssa, float* %arrayidx8, align 4
57 ret void
58 }
59
60 ; Function Attrs: nounwind readnone
61 declare i64 @_Z13get_global_idj(i32) #1
62
63 ; Function Attrs: nounwind readnone speculatable
64 declare float @llvm.fmuladd.f32(float, float, float) #2
65
66 attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
67 attributes #1 = { nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
68 attributes #2 = { nounwind readnone speculatable }
69 attributes #3 = { nounwind readnone }
70
71 !llvm.module.flags = !{!0}
72 !llvm.ident = !{!1}
73
74 !0 = !{i32 1, !"wchar_size", i32 4}
75 !1 = !{!"clang version 5.0.0 (trunk 303846) (llvm/trunk 303834)"}
76 !2 = !{i32 1, i32 1, i32 1, i32 0}
77 !3 = !{!"none", !"none", !"none", !"none"}
78 !4 = !{!"float*", !"float*", !"float*", !"long"}
79 !5 = !{!"", !"", !"", !""}