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 written to. 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; if (i > 0) { 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 %A_idx = getelementptr inbounds double, double* %A, i32 %j 33 %init = load double, double* %A_idx 34 %guard.cmp = icmp sle i32 %n,0 35 br i1 %guard.cmp, label %reduction.skip, label %reduction.for 36 37 reduction.for: 38 %i = phi i32 [0, %reduction.guard], [%i.inc, %reduction.inc] 39 %phi = phi double [%init, %reduction.guard], [%add, %reduction.inc] 40 br label %body 41 42 43 44 body: 45 %add = fadd double %phi, 4.2 46 br label %reduction.inc 47 48 49 50 reduction.inc: 51 %i.inc = add nuw nsw i32 %i, 1 52 %i.cmp = icmp slt i32 %i.inc, %n 53 br i1 %i.cmp, label %reduction.for, label %reduction.exit 54 55 reduction.exit: 56 store double %add, double* %A_idx 57 br label %reduction.skip 58 59 reduction.skip: 60 br label %outer.inc 61 62 63 64outer.inc: 65 %j.inc = add nuw nsw i32 %j, 1 66 br label %outer.for 67 68outer.exit: 69 br label %return 70 71return: 72 ret void 73} 74 75 76; CHECK: Statistics { 77; CHECK: Compatible overwrites: 1 78; CHECK: Overwrites mapped to: 1 79; CHECK: Value scalars mapped: 2 80; CHECK: PHI scalars mapped: 1 81; CHECK: } 82 83; CHECK: After accesses { 84; CHECK-NEXT: Stmt_reduction_guard 85; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 0] 86; CHECK-NEXT: [n] -> { Stmt_reduction_guard[i0] -> MemRef_A[i0] }; 87; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 88; CHECK-NEXT: [n] -> { Stmt_reduction_guard[i0] -> MemRef_phi__phi[] }; 89; CHECK-NEXT: new: [n] -> { Stmt_reduction_guard[i0] -> MemRef_A[i0] : n > 0 }; 90; CHECK-NEXT: Stmt_reduction_for 91; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 92; CHECK-NEXT: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_phi__phi[] }; 93; CHECK-NEXT: new: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] }; 94; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 95; CHECK-NEXT: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_phi[] }; 96; CHECK-NEXT: new: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] }; 97; CHECK-NEXT: Stmt_body 98; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 99; CHECK-NEXT: [n] -> { Stmt_body[i0, i1] -> MemRef_add[] }; 100; CHECK-NEXT: new: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] }; 101; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 102; CHECK-NEXT: [n] -> { Stmt_body[i0, i1] -> MemRef_phi[] }; 103; CHECK-NEXT: new: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] }; 104; CHECK-NEXT: Stmt_reduction_inc 105; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 106; CHECK-NEXT: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_add[] }; 107; CHECK-NEXT: new: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] }; 108; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 109; CHECK-NEXT: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_phi__phi[] }; 110; CHECK-NEXT: new: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] : i1 <= -2 + n }; 111; CHECK-NEXT: Stmt_reduction_exit 112; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0] 113; CHECK-NEXT: [n] -> { Stmt_reduction_exit[i0] -> MemRef_A[i0] }; 114; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 115; CHECK-NEXT: [n] -> { Stmt_reduction_exit[i0] -> MemRef_add[] }; 116; CHECK-NEXT: new: [n] -> { Stmt_reduction_exit[i0] -> MemRef_A[i0] }; 117; CHECK-NEXT: } 118