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:             [LB, UB] -> { Stmt_for_body[i0] -> MemRef_LBptr[0] };
6; CHECK-NEXT:         Execution Context: [LB, UB] -> {  :  }
7; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
8; CHECK-NEXT:             [LB, UB] -> { Stmt_do_cond[i0, i1] -> MemRef_UBptr[0] };
9; CHECK-NEXT:         Execution Context: [LB, UB] -> {  :  }
10; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
11; CHECK-NEXT:             [LB, UB] -> { Stmt_if_then[i0, i1] -> MemRef_V[0] };
12; CHECK-NEXT:         Execution Context: [LB, UB] -> {  : LB >= 6 or (UB > LB and UB >= 6) }
13; CHECK-NEXT:         ReadAccess :=    [Reduction Type: NONE] [Scalar: 0]
14; CHECK-NEXT:             [LB, UB] -> { Stmt_if_else[i0, i1] -> MemRef_U[0] };
15; CHECK-NEXT:         Execution Context: [LB, UB] -> {  : LB <= 5 }
16; CHECK-NEXT: }
17;
18;    void f(int *restrict A, int *restrict V, int *restrict U, int *restrict UB,
19;           int *restrict LB) {
20;      for (int i = 0; i < 100; i++) {
21;        int j = /* invariant load */ *LB;
22;        do {
23;          if (j > 5)
24;            A[i] += /* invariant load */ *V;
25;          else
26;            A[i] += /* invariant load */ *U;
27;        } while (j++ < /* invariant load */ *UB);
28;      }
29;    }
30;
31target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
32
33define void @f(i32* noalias %A, i32* noalias %V, i32* noalias %U, i32* noalias %UBptr, i32* noalias %LBptr) {
34entry:
35  br label %for.cond
36
37for.cond:                                         ; preds = %for.inc, %entry
38  %indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
39  %exitcond = icmp ne i64 %indvars.iv, 100
40  br i1 %exitcond, label %for.body, label %for.end
41
42for.body:                                         ; preds = %for.cond
43  %LB = load i32, i32* %LBptr, align 4
44  br label %do.body
45
46do.body:                                          ; preds = %do.cond, %for.body
47  %j.0 = phi i32 [ %LB, %for.body ], [ %inc, %do.cond ]
48  %cmp1 = icmp sgt i32 %j.0, 5
49  br i1 %cmp1, label %if.then, label %if.else
50
51if.then:                                          ; preds = %do.body
52  %tmp1 = load i32, i32* %V, align 4
53  %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
54  %tmp2 = load i32, i32* %arrayidx, align 4
55  %add = add nsw i32 %tmp2, %tmp1
56  store i32 %add, i32* %arrayidx, align 4
57  br label %if.end
58
59if.else:                                          ; preds = %do.body
60  %tmp3 = load i32, i32* %U, align 4
61  %arrayidx3 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
62  %tmp4 = load i32, i32* %arrayidx3, align 4
63  %add4 = add nsw i32 %tmp4, %tmp3
64  store i32 %add4, i32* %arrayidx3, align 4
65  br label %if.end
66
67if.end:                                           ; preds = %if.else, %if.then
68  br label %do.cond
69
70do.cond:                                          ; preds = %if.end
71  %inc = add nsw i32 %j.0, 1
72  %UB = load i32, i32* %UBptr, align 4
73  %cmp5 = icmp slt i32 %j.0, %UB
74  br i1 %cmp5, label %do.body, label %do.end
75
76do.end:                                           ; preds = %do.cond
77  br label %for.inc
78
79for.inc:                                          ; preds = %do.end
80  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
81  br label %for.cond
82
83for.end:                                          ; preds = %for.cond
84  ret void
85}
86