1; RUN: opt %loadPolly -polly-scops -analyze < %s \
2; RUN:  -polly-invariant-load-hoisting \
3; RUN:  | FileCheck %s
4
5; Make sure we choose a canonical element that is not the first invariant load,
6; but the first that is an array base pointer.
7
8; CHECK:     Statements {
9; CHECK-NEXT:     	Stmt_body0
10; CHECK-NEXT:             Domain :=
11; CHECK-NEXT:                 { Stmt_body0[i0] : 0 <= i0 <= 1022 };
12; CHECK-NEXT:             Schedule :=
13; CHECK-NEXT:                 { Stmt_body0[i0] -> [i0, 0] };
14; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
15; CHECK-NEXT:                 { Stmt_body0[i0] -> MemRef_X[0] };
16; CHECK-NEXT:     	Stmt_body1
17; CHECK-NEXT:             Domain :=
18; CHECK-NEXT:                 { Stmt_body1[i0] : 0 <= i0 <= 1022 };
19; CHECK-NEXT:             Schedule :=
20; CHECK-NEXT:                 { Stmt_body1[i0] -> [i0, 1] };
21; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
22; CHECK-NEXT:                 { Stmt_body1[i0] -> MemRef_baseB[0] };
23; CHECK-NEXT:     	Stmt_body2
24; CHECK-NEXT:             Domain :=
25; CHECK-NEXT:                 { Stmt_body2[i0] : 0 <= i0 <= 1022 };
26; CHECK-NEXT:             Schedule :=
27; CHECK-NEXT:                 { Stmt_body2[i0] -> [i0, 2] };
28; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
29; CHECK-NEXT:                 { Stmt_body2[i0] -> MemRef_X[0] };
30; CHECK-NEXT:             ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
31; CHECK-NEXT:                 { Stmt_body2[i0] -> MemRef_ptr[] };
32; CHECK-NEXT:     	Stmt_body3
33; CHECK-NEXT:             Domain :=
34; CHECK-NEXT:                 { Stmt_body3[i0] : 0 <= i0 <= 1022 };
35; CHECK-NEXT:             Schedule :=
36; CHECK-NEXT:                 { Stmt_body3[i0] -> [i0, 3] };
37; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
38; CHECK-NEXT:                 { Stmt_body3[i0] -> MemRef_baseB[0] };
39; CHECK-NEXT:     	Stmt_body4
40; CHECK-NEXT:             Domain :=
41; CHECK-NEXT:                 { Stmt_body4[i0] : 0 <= i0 <= 1022 };
42; CHECK-NEXT:             Schedule :=
43; CHECK-NEXT:                 { Stmt_body4[i0] -> [i0, 4] };
44; CHECK-NEXT:             MustWriteAccess :=	[Reduction Type: NONE] [Scalar: 0]
45; CHECK-NEXT:                 { Stmt_body4[i0] -> MemRef_X[0] };
46; CHECK-NEXT:             ReadAccess :=	[Reduction Type: NONE] [Scalar: 1]
47; CHECK-NEXT:                 { Stmt_body4[i0] -> MemRef_ptr[] };
48; CHECK-NEXT:     }
49
50define void @foo(float** %A, float** %X) {
51start:
52  br label %loop
53
54loop:
55  %indvar = phi i64 [0, %start], [%indvar.next, %latch]
56  %indvar.next = add nsw i64 %indvar, 1
57  %icmp = icmp slt i64 %indvar.next, 1024
58  br i1 %icmp, label %body0, label %exit
59
60body0:
61  %ptr = load float*, float** %A
62  store float* %ptr, float** %X
63  br label %body1
64
65body1:
66  %baseA = load float*, float** %A
67  store float 42.0, float* %baseA
68  br label %body2
69
70body2:
71  %ptr2 = load float*, float** %A
72  store float* %ptr, float** %X
73  br label %body3
74
75body3:
76  %baseB = load float*, float** %A
77  store float 42.0, float* %baseB
78  br label %body4
79
80body4:
81  %ptr3 = load float*, float** %A
82  store float* %ptr, float** %X
83  br label %latch
84
85latch:
86  br label %loop
87
88exit:
89  ret void
90
91}
92