1 ; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-print-delicm -disable-output < %s | FileCheck %s -match-full-lines
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.
7 ; void func(double *A) {
8 ; for (int j = 0; j < 2; j += 1) { /* outer */
10 ; for (int i = 0; i < n; i += 1) /* reduction */
16 define void @func(i32 %n, ptr noalias nonnull %A) {
18 br label %outer.preheader
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
30 %A_idx = getelementptr inbounds double, ptr %A, i32 %j
31 %init = load double, ptr %A_idx
32 %guard.cmp = icmp sle i32 %n,0
33 br i1 %guard.cmp, label %reduction.exit, label %reduction.for
36 %i = phi i32 [0, %reduction.guard], [%i.inc, %reduction.inc]
37 %phi = phi double [%init, %reduction.guard], [%add, %reduction.inc]
43 %add = fadd double %phi, 4.2
44 br label %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
54 %result = phi double [%init, %reduction.guard], [%add, %reduction.inc]
55 store double %result, ptr %A_idx
61 %j.inc = add nuw nsw i32 %j, 1
73 ; CHECK: Compatible overwrites: 1
74 ; CHECK: Overwrites mapped to: 1
75 ; CHECK: Value scalars mapped: 2
76 ; CHECK: PHI scalars mapped: 2
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] };