1; RUN: opt %loadPolly -basic-aa -loop-rotate -indvars       -polly-prepare -polly-scops -analyze < %s | FileCheck %s
2; RUN: opt %loadPolly -basic-aa -loop-rotate -indvars -licm -polly-prepare -polly-scops -analyze < %s | FileCheck %s
3;
4; XFAIL: *
5;
6; Even ScopDetection fails here after LICM because of PHI in exit node.
7;
8;    void foo(unsigned long *restrict A, unsigned long *restrict B,
9;             unsigned long j) {
10;      for (unsigned long i = 0; i < 100; i++)
11;        for (unsigned long k = 0; k < 100; k++)
12;          A[j] += B[i + k];
13;    }
14;
15target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
16
17define void @foo(i64* noalias %A, i64* noalias %B, i64 %j) {
18entry:
19  br label %for.cond
20
21for.cond:                                         ; preds = %for.inc.6, %entry
22  %i.0 = phi i64 [ 0, %entry ], [ %inc7, %for.inc.6 ]
23  %exitcond1 = icmp ne i64 %i.0, 100
24  br i1 %exitcond1, label %for.body, label %for.end.8
25
26for.body:                                         ; preds = %for.cond
27  br label %for.cond.1
28
29for.cond.1:                                       ; preds = %for.inc, %for.body
30  %k.0 = phi i64 [ 0, %for.body ], [ %inc, %for.inc ]
31  %exitcond = icmp ne i64 %k.0, 100
32  br i1 %exitcond, label %for.body.3, label %for.end
33
34for.body.3:                                       ; preds = %for.cond.1
35  %add = add nuw nsw i64 %i.0, %k.0
36  %arrayidx = getelementptr inbounds i64, i64* %B, i64 %add
37  %tmp = load i64, i64* %arrayidx, align 8
38  %arrayidx4 = getelementptr inbounds i64, i64* %A, i64 %j
39  %tmp2 = load i64, i64* %arrayidx4, align 8
40  %add5 = add i64 %tmp2, %tmp
41  store i64 %add5, i64* %arrayidx4, align 8
42  br label %for.inc
43
44for.inc:                                          ; preds = %for.body.3
45  %inc = add nuw nsw i64 %k.0, 1
46  br label %for.cond.1
47
48for.end:                                          ; preds = %for.cond.1
49  br label %for.inc.6
50
51for.inc.6:                                        ; preds = %for.end
52  %inc7 = add nuw nsw i64 %i.0, 1
53  br label %for.cond
54
55for.end.8:                                        ; preds = %for.cond
56  ret void
57}
58
59
60; CHECK: Statements {
61; CHECK:     Stmt_for_body_3
62; CHECK-DAG:    ReadAccess :=       [Reduction Type: NONE] [Scalar: 0]
63; CHECK-NEXT:       [j] -> { Stmt_for_body_3[i0, i1] -> MemRef_B[i0 + i1] };
64; CHECK-DAG:    ReadAccess :=       [Reduction Type: +] [Scalar: 0]
65; CHECK-NEXT:       [j] -> { Stmt_for_body_3[i0, i1] -> MemRef_A[j] };
66; CHECK-DAG:    MustWriteAccess :=  [Reduction Type: +] [Scalar: 0]
67; CHECK-NEXT:       [j] -> { Stmt_for_body_3[i0, i1] -> MemRef_A[j] };
68; CHECK: }
69