1; RUN: opt %loadPolly -basic-aa -polly-scops \
2; RUN: -polly-invariant-load-hoisting=true -analyze < %s | FileCheck %s
3
4; void f(long A[], int N, int *init_ptr) {
5;   long i, j;
6;
7;   for (i = 0; i < N; ++i) {
8;     init = *init_ptr;
9;     for (i = 0; i < N; ++i) {
10;       A[i] = init + 2;
11;     }
12;   }
13; }
14
15target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
16
17; Function Attrs: nounwind
18; CHECK: Invariant
19; CHECK:           ReadAccess :=       [Reduction Type: NONE] [Scalar: 0]
20; CHECK-NEXT:          MemRef_init_ptr[0]
21
22define void @f(i64* noalias %A, i64 %N, i64* noalias %init_ptr) #0 {
23entry:
24  br label %for.i
25
26for.i:                                            ; preds = %for.i.end, %entry
27  %indvar.i = phi i64 [ 0, %entry ], [ %indvar.i.next, %for.i.end ]
28  %indvar.i.next = add nsw i64 %indvar.i, 1
29  br label %entry.next
30
31entry.next:                                       ; preds = %for.i
32  %init = load i64, i64* %init_ptr
33; CHECK-NOT: Stmt_entry_next
34  br label %for.j
35
36for.j:                                            ; preds = %for.j, %entry.next
37  %indvar.j = phi i64 [ 0, %entry.next ], [ %indvar.j.next, %for.j ]
38  %init_plus_two = add i64 %init, 2
39; CHECK-LABEL: Stmt_for_j
40; CHECK:           ReadAccess :=       [Reduction Type: NONE] [Scalar: 1]
41; CHECK-NEXT:          [N] -> { Stmt_for_j[i0, i1] -> MemRef_init[] };
42; CHECK:           MustWriteAccess :=  [Reduction Type: NONE] [Scalar: 0]
43; CHECK-NEXT:          [N] -> { Stmt_for_j[i0, i1] -> MemRef_A[i1] };
44  %scevgep = getelementptr i64, i64* %A, i64 %indvar.j
45  store i64 %init_plus_two, i64* %scevgep
46  %indvar.j.next = add nsw i64 %indvar.j, 1
47  %exitcond.j = icmp eq i64 %indvar.j.next, %N
48  br i1 %exitcond.j, label %for.i.end, label %for.j
49
50for.i.end:                                        ; preds = %for.j
51  %exitcond.i = icmp eq i64 %indvar.i.next, %N
52  br i1 %exitcond.i, label %return, label %for.i
53
54return:                                           ; preds = %for.i.end
55  ret void
56}
57
58attributes #0 = { nounwind }
59