1; RUN: opt %loadPolly -polly-scops -polly-invariant-load-hoisting=true -analyze < %s | FileCheck %s
2;
3; CHECK:      Invariant Accesses: {
4; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
5; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_cond[i0] -> MemRef_bounds[2] };
6; CHECK-NEXT:         Execution Context: [bounds2, bounds1, bounds0] -> {  :  }
7; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
8; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_cond_1[i0, i1] -> MemRef_bounds[1] };
9; CHECK-NEXT:         Execution Context: [bounds2, bounds1, bounds0] -> {  :  }
10; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
11; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_cond_4[i0, i1, i2] -> MemRef_bounds[0] };
12; CHECK-NEXT:         Execution Context: [bounds2, bounds1, bounds0] -> {  :  }
13; CHECK-NEXT: }
14;
15; CHECK:      p0: %bounds2
16; CHECK-NEXT: p1: %bounds1
17; CHECK-NEXT: p2: %bounds0
18;
19; CHECK:      Statements {
20; CHECK-NEXT:     Stmt_for_body_6
21; CHECK-NEXT:         Domain :=
22; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_body_6[i0, i1, i2] : 0 <= i0 < bounds2 and 0 <= i1 < bounds1 and 0 <= i2 < bounds0 };
23; CHECK-NEXT:         Schedule :=
24; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_body_6[i0, i1, i2] -> [i0, i1, i2] };
25; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
26; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_body_6[i0, i1, i2] -> MemRef_data[i0, i1, i2] };
27; CHECK-NEXT:         MustWriteAccess :=    [Reduction Type: NONE] [Scalar: 0]
28; CHECK-NEXT:             [bounds2, bounds1, bounds0] -> { Stmt_for_body_6[i0, i1, i2] -> MemRef_data[i0, i1, i2] };
29; CHECK-NEXT: }
30;
31;    int bounds[3];
32;    double data[1024][1024][1024];
33;
34;    void foo() {
35;      int i, j, k;
36;      for (k = 0; k < bounds[2]; k++)
37;        for (j = 0; j < bounds[1]; j++)
38;          for (i = 0; i < bounds[0]; i++)
39;            data[k][j][i] += i + j + k;
40;    }
41;
42target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
43
44@bounds = common global [3 x i32] zeroinitializer, align 4
45@data = common global [1024 x [1024 x [1024 x double]]] zeroinitializer, align 16
46
47define void @foo() {
48entry:
49  br label %for.cond
50
51for.cond:                                         ; preds = %for.inc.16, %entry
52  %indvars.iv5 = phi i64 [ %indvars.iv.next6, %for.inc.16 ], [ 0, %entry ]
53  %bounds2 = load i32, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @bounds, i64 0, i64 2), align 4
54  %tmp7 = sext i32 %bounds2 to i64
55  %cmp = icmp slt i64 %indvars.iv5, %tmp7
56  br i1 %cmp, label %for.body, label %for.end.18
57
58for.body:                                         ; preds = %for.cond
59  br label %for.cond.1
60
61for.cond.1:                                       ; preds = %for.inc.13, %for.body
62  %indvars.iv3 = phi i64 [ %indvars.iv.next4, %for.inc.13 ], [ 0, %for.body ]
63  %bounds1 = load i32, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @bounds, i64 0, i64 1), align 4
64  %tmp9 = sext i32 %bounds1 to i64
65  %cmp2 = icmp slt i64 %indvars.iv3, %tmp9
66  br i1 %cmp2, label %for.body.3, label %for.end.15
67
68for.body.3:                                       ; preds = %for.cond.1
69  br label %for.cond.4
70
71for.cond.4:                                       ; preds = %for.inc, %for.body.3
72  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %for.body.3 ]
73  %bounds0 = load i32, i32* getelementptr inbounds ([3 x i32], [3 x i32]* @bounds, i64 0, i64 0), align 4
74  %tmp11 = sext i32 %bounds0 to i64
75  %cmp5 = icmp slt i64 %indvars.iv, %tmp11
76  br i1 %cmp5, label %for.body.6, label %for.end
77
78for.body.6:                                       ; preds = %for.cond.4
79  %tmp12 = add nsw i64 %indvars.iv, %indvars.iv3
80  %tmp13 = add nsw i64 %tmp12, %indvars.iv5
81  %tmp14 = trunc i64 %tmp13 to i32
82  %conv = sitofp i32 %tmp14 to double
83  %arrayidx11 = getelementptr inbounds [1024 x [1024 x [1024 x double]]], [1024 x [1024 x [1024 x double]]]* @data, i64 0, i64 %indvars.iv5, i64 %indvars.iv3, i64 %indvars.iv
84  %tmp15 = load double, double* %arrayidx11, align 8
85  %add12 = fadd double %tmp15, %conv
86  store double %add12, double* %arrayidx11, align 8
87  br label %for.inc
88
89for.inc:                                          ; preds = %for.body.6
90  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
91  br label %for.cond.4
92
93for.end:                                          ; preds = %for.cond.4
94  br label %for.inc.13
95
96for.inc.13:                                       ; preds = %for.end
97  %indvars.iv.next4 = add nuw nsw i64 %indvars.iv3, 1
98  br label %for.cond.1
99
100for.end.15:                                       ; preds = %for.cond.1
101  br label %for.inc.16
102
103for.inc.16:                                       ; preds = %for.end.15
104  %indvars.iv.next6 = add nuw nsw i64 %indvars.iv5, 1
105  br label %for.cond
106
107for.end.18:                                       ; preds = %for.cond
108  ret void
109}
110