1; RUN: opt %loadPolly -polly-stmt-granularity=bb -polly-delicm -analyze < %s | FileCheck %s -match-full-lines 2; 3; Load (but not store) of A[j] hoisted, reduction only over some iterations. 4; 5; void func(double *A) { 6; for (int j = 0; j < 2; j += 1) { /* outer */ 7; double phi = 0.0; 8; for (int i = 0; i < 4; i += 1) { /* reduction */ 9; if (i != 2) 10; phi += 4.2; 11; A[j] = phi; 12; } 13; } 14; } 15; 16define void @func(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 br label %reduction.for 31 32 reduction.for: 33 %i = phi i32 [0, %reduction.preheader], [%i.inc, %reduction.inc] 34 %phi = phi double [0.0, %reduction.preheader], [%join, %reduction.inc] 35 br label %body 36 37 38 39 body: 40 %cond = icmp ne i32 %i, 2 41 br i1 %cond, label %body_true, label %body_join 42 43 body_true: 44 %add = fadd double %phi, 4.2 45 br label %body_join 46 47 body_join: 48 %join = phi double [%phi, %body], [%add, %body_true] 49 %A_idx = getelementptr inbounds double, double* %A, i32 %j 50 store double %join, double* %A_idx 51 br label %reduction.inc 52 53 54 55 reduction.inc: 56 %i.inc = add nuw nsw i32 %i, 1 57 %i.cmp = icmp slt i32 %i.inc, 4 58 br i1 %i.cmp, label %reduction.for, label %reduction.exit 59 60 reduction.exit: 61 br label %outer.inc 62 63 64 65outer.inc: 66 %j.inc = add nuw nsw i32 %j, 1 67 br label %outer.for 68 69outer.exit: 70 br label %return 71 72return: 73 ret void 74} 75 76 77; CHECK: Statistics { 78; CHECK: Compatible overwrites: 1 79; CHECK: Overwrites mapped to: 1 80; CHECK: Value scalars mapped: 2 81; CHECK: PHI scalars mapped: 2 82; CHECK: } 83 84; CHECK: After accesses { 85; CHECK-NEXT: Stmt_reduction_preheader 86; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 87; CHECK-NEXT: { Stmt_reduction_preheader[i0] -> MemRef_phi__phi[] }; 88; CHECK-NEXT: new: { Stmt_reduction_preheader[i0] -> MemRef_A[i0] }; 89; CHECK-NEXT: Stmt_reduction_for 90; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 91; CHECK-NEXT: { Stmt_reduction_for[i0, i1] -> MemRef_phi__phi[] }; 92; CHECK-NEXT: new: { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] }; 93; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 94; CHECK-NEXT: { Stmt_reduction_for[i0, i1] -> MemRef_phi[] }; 95; CHECK-NEXT: new: { Stmt_reduction_for[i0, i1] -> MemRef_A[i0] }; 96; CHECK-NEXT: Stmt_body 97; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 98; CHECK-NEXT: { Stmt_body[i0, i1] -> MemRef_phi[] }; 99; CHECK-NEXT: new: { Stmt_body[i0, i1] -> MemRef_A[i0] }; 100; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 101; CHECK-NEXT: { Stmt_body[i0, i1] -> MemRef_join__phi[] }; 102; CHECK-NEXT: new: { Stmt_body[i0, 2] -> MemRef_A[i0] }; 103; CHECK-NEXT: Stmt_body_true 104; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 105; CHECK-NEXT: { Stmt_body_true[i0, i1] -> MemRef_phi[] }; 106; CHECK-NEXT: new: { Stmt_body_true[i0, i1] -> MemRef_A[i0] : i1 <= 1; Stmt_body_true[i0, 3] -> MemRef_A[i0] }; 107; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 108; CHECK-NEXT: { Stmt_body_true[i0, i1] -> MemRef_join__phi[] }; 109; CHECK-NEXT: new: { Stmt_body_true[i0, i1] -> MemRef_A[i0] : i1 <= 1; Stmt_body_true[i0, 3] -> MemRef_A[i0] }; 110; CHECK-NEXT: Stmt_body_join 111; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 112; CHECK-NEXT: { Stmt_body_join[i0, i1] -> MemRef_join[] }; 113; CHECK-NEXT: new: { Stmt_body_join[i0, i1] -> MemRef_A[i0] }; 114; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 115; CHECK-NEXT: { Stmt_body_join[i0, i1] -> MemRef_join__phi[] }; 116; CHECK-NEXT: new: { Stmt_body_join[i0, i1] -> MemRef_A[i0] }; 117; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 0] 118; CHECK-NEXT: { Stmt_body_join[i0, i1] -> MemRef_A[i0] }; 119; CHECK-NEXT: Stmt_reduction_inc 120; CHECK-NEXT: ReadAccess := [Reduction Type: NONE] [Scalar: 1] 121; CHECK-NEXT: { Stmt_reduction_inc[i0, i1] -> MemRef_join[] }; 122; CHECK-NEXT: new: { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] }; 123; CHECK-NEXT: MustWriteAccess := [Reduction Type: NONE] [Scalar: 1] 124; CHECK-NEXT: { Stmt_reduction_inc[i0, i1] -> MemRef_phi__phi[] }; 125; CHECK-NEXT: new: { Stmt_reduction_inc[i0, i1] -> MemRef_A[i0] : i1 <= 2 }; 126; CHECK-NEXT: } 127