1; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-delicm -analyze < %s | FileCheck %s -match-full-lines
2;
3; Reduction over parametric number of elements and a loopguard if the
4; reduction loop is not executed at all, such that A[j] is also not accessed.
5; Reduction variable promoted to register.
6;
7;    void func(double *A) {
8;      for (int j = 0; j < 2; j += 1) { /* outer */
9;        if (i > 0) {
10;          double phi = A[j];
11;          for (int i = 0; i < n; i += 1) /* reduction */
12;            phi += 4.2;
13;          A[j] = phi;
14;        }
15;      }
16;    }
17;
18define void @func(i32 %n, double* noalias nonnull %A) {
19entry:
20  br label %outer.preheader
21
22outer.preheader:
23  br label %outer.for
24
25outer.for:
26  %j = phi i32 [0, %outer.preheader], [%j.inc, %outer.inc]
27  %j.cmp = icmp slt i32 %j, 2
28  br i1 %j.cmp, label %reduction.guard, label %outer.exit
29
30
31    reduction.guard:
32      %guard.cmp = icmp sle i32 %n,0
33      br i1 %guard.cmp, label %reduction.skip, label %reduction.preheader
34
35    reduction.preheader:
36      %A_idx = getelementptr inbounds double, double* %A, i32 %j
37      %init = load double, double* %A_idx
38      br label %reduction.for
39
40    reduction.for:
41      %i = phi i32 [0, %reduction.preheader], [%i.inc, %reduction.inc]
42      %phi = phi double [%init, %reduction.preheader], [%add, %reduction.inc]
43      br label %body
44
45
46
47        body:
48          %add = fadd double %phi, 4.2
49          br label %reduction.inc
50
51
52
53    reduction.inc:
54      %i.inc = add nuw nsw i32 %i, 1
55      %i.cmp = icmp slt i32 %i.inc, %n
56      br i1 %i.cmp, label %reduction.for, label %reduction.exit
57
58    reduction.exit:
59      store double %add, double* %A_idx
60      br label %reduction.skip
61
62    reduction.skip:
63      br label %outer.inc
64
65
66
67outer.inc:
68  %j.inc = add nuw nsw i32 %j, 1
69  br label %outer.for
70
71outer.exit:
72  br label %return
73
74return:
75  ret void
76}
77
78
79; CHECK: Statistics {
80; CHECK:     Compatible overwrites: 1
81; CHECK:     Overwrites mapped to:  1
82; CHECK:     Value scalars mapped:  2
83; CHECK:     PHI scalars mapped:    1
84; CHECK: }
85
86; CHECK:      After accesses {
87; CHECK-NEXT:     Stmt_reduction_preheader
88; CHECK-NEXT:             ReadAccess :=       [Reduction Type: NONE] [Scalar: 0]
89; CHECK-NEXT:                 [n] -> { Stmt_reduction_preheader[i0] -> MemRef_A[i0] };
90; CHECK-NEXT:             MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
91; CHECK-NEXT:                 [n] -> { Stmt_reduction_preheader[i0] -> MemRef_phi__phi[] };
92; CHECK-NEXT:            new: [n] -> { Stmt_reduction_preheader[i0] -> MemRef_A[i0] };
93; CHECK-NEXT:     Stmt_reduction_for
94; CHECK-NEXT:             ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
95; CHECK-NEXT:                 [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_phi__phi[] };
96; CHECK-NEXT:            new: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] };
97; CHECK-NEXT:             MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
98; CHECK-NEXT:                 [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_phi[] };
99; CHECK-NEXT:            new: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] };
100; CHECK-NEXT:     Stmt_body
101; CHECK-NEXT:             MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
102; CHECK-NEXT:                 [n] -> { Stmt_body[i0, i1] -> MemRef_add[] };
103; CHECK-NEXT:            new: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] };
104; CHECK-NEXT:             ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
105; CHECK-NEXT:                 [n] -> { Stmt_body[i0, i1] -> MemRef_phi[] };
106; CHECK-NEXT:            new: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] };
107; CHECK-NEXT:     Stmt_reduction_inc
108; CHECK-NEXT:             ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
109; CHECK-NEXT:                 [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_add[] };
110; CHECK-NEXT:            new: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] };
111; CHECK-NEXT:             MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 1]
112; CHECK-NEXT:                 [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_phi__phi[] };
113; CHECK-NEXT:            new: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] : i1 <= -2 + n };
114; CHECK-NEXT:     Stmt_reduction_exit
115; CHECK-NEXT:             MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
116; CHECK-NEXT:                 [n] -> { Stmt_reduction_exit[i0] -> MemRef_A[i0] };
117; CHECK-NEXT:             ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
118; CHECK-NEXT:                 [n] -> { Stmt_reduction_exit[i0] -> MemRef_add[] };
119; CHECK-NEXT:            new: [n] -> { Stmt_reduction_exit[i0] -> MemRef_A[i0] };
120; CHECK-NEXT: }
121