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. Load hoisted before loop. 5; 6; void func(double *A) { 7; for (int j = 0; j < 2; j += 1) { /* outer */ 8; double phi = 0.0; 9; for (int i = 0; i < n; i += 1) { /* reduction */ 10; phi += 4.2; 11; A[j] = phi; 12; } 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.preheader, label %outer.exit 27 28 29 reduction.preheader: 30 %guard.cmp = icmp sle i32 %n,0 31 br i1 %guard.cmp, label %reduction.exit, label %reduction.for 32 33 reduction.for: 34 %i = phi i32 [0, %reduction.preheader], [%i.inc, %reduction.inc] 35 %phi = phi double [0.0, %reduction.preheader], [%add, %reduction.inc] 36 br label %body 37 38 39 40 body: 41 %add = fadd double %phi, 4.2 42 %A_idx = getelementptr inbounds double, double* %A, i32 %j 43 store double %add, double* %A_idx 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 br label %outer.inc 55 56 57 58outer.inc: 59 %j.inc = add nuw nsw i32 %j, 1 60 br label %outer.for 61 62outer.exit: 63 br label %return 64 65return: 66 ret void 67} 68 69 70; CHECK: Statistics { 71; CHECK: Compatible overwrites: 1 72; CHECK: Overwrites mapped to: 1 73; CHECK: Value scalars mapped: 2 74; CHECK: PHI scalars mapped: 1 75; CHECK: } 76 77; CHECK: After accesses { 78; CHECK-NEXT: Stmt_reduction_preheader 79; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 80; CHECK-NEXT: [n] -> { Stmt_reduction_preheader[i0] -> MemRef_phi__phi[] }; 81; CHECK-NEXT: new: [n] -> { Stmt_reduction_preheader[i0] -> MemRef_A[i0] : n > 0 }; 82; CHECK-NEXT: Stmt_reduction_for 83; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 84; CHECK-NEXT: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_phi__phi[] }; 85; CHECK-NEXT: new: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] }; 86; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 87; CHECK-NEXT: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_phi[] }; 88; CHECK-NEXT: new: [n] -> { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] }; 89; CHECK-NEXT: Stmt_body 90; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 91; CHECK-NEXT: [n] -> { Stmt_body[i0, i1] -> MemRef_add[] }; 92; CHECK-NEXT: new: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] }; 93; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 94; CHECK-NEXT: [n] -> { Stmt_body[i0, i1] -> MemRef_phi[] }; 95; CHECK-NEXT: new: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] }; 96; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0] 97; CHECK-NEXT: [n] -> { Stmt_body[i0, i1] -> MemRef_A[i0] }; 98; CHECK-NEXT: Stmt_reduction_inc 99; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 100; CHECK-NEXT: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_add[] }; 101; CHECK-NEXT: new: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] }; 102; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 103; CHECK-NEXT: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_phi__phi[] }; 104; CHECK-NEXT: new: [n] -> { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] : i1 <= -2 + n }; 105; CHECK-NEXT: } 106