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