1; RUN: opt %loadPolly -basic-aa -polly-ast -analyze < %s | FileCheck %s
2
3;#include <string.h>
4;#define N 1024
5;int A[N];
6;int B[N];
7;
8;void loop_with_condition() {
9;  int i;
10;
11;  __sync_synchronize();
12;  for (i = 0; i < N; i++) {
13;    if (i <= N / 2)
14;      A[i] = 1;
15;    else
16;      A[i] = 2;
17;    B[i] = 3;
18;  }
19;  __sync_synchronize();
20;}
21;
22;int main () {
23;  int i;
24;
25;  memset(A, 0, sizeof(int) * N);
26;  memset(B, 0, sizeof(int) * N);
27;
28;  loop_with_condition();
29;
30;  for (i = 0; i < N; i++)
31;    if (B[i] != 3)
32;      return 1;
33;
34;  for (i = 0; i < N; i++)
35;    if (i <= N / 2 && A[i] != 1)
36;      return 1;
37;    else if (i > N / 2 && A[i] != 2)
38;      return 1;
39;  return 0;
40;}
41
42target 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-n8:16:32:64"
43
44@A = common global [1024 x i32] zeroinitializer, align 16 ; <[1024 x i32]*> [#uses=4]
45@B = common global [1024 x i32] zeroinitializer, align 16 ; <[1024 x i32]*> [#uses=4]
46
47define void @loop_with_condition() nounwind {
48bb0:
49  fence seq_cst
50  br label %bb1
51
52bb1:
53  %indvar = phi i64 [ %indvar.next, %bb7 ], [ 0, %bb0 ] ; <i64> [#uses=5]
54  %scevgep = getelementptr [1024 x i32], [1024 x i32]* @A, i64 0, i64 %indvar ; <i32*> [#uses=2]
55  %scevgep1 = getelementptr [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvar ; <i32*> [#uses=1]
56  %i.0 = trunc i64 %indvar to i32                 ; <i32> [#uses=1]
57  %exitcond = icmp ne i64 %indvar, 1024           ; <i1> [#uses=1]
58  br i1 %exitcond, label %bb2, label %bb8
59
60bb2:
61  %var3 = icmp sle i32 %i.0, 512                     ; <i1> [#uses=1]
62  br i1 %var3, label %bb4, label %bb5
63
64bb4:
65  store i32 1, i32* %scevgep
66  br label %bb6
67
68bb5:
69  store i32 2, i32* %scevgep
70  br label %bb6
71
72bb6:
73  store i32 3, i32* %scevgep1
74  br label %bb7
75
76bb7:
77  %indvar.next = add i64 %indvar, 1               ; <i64> [#uses=1]
78  br label %bb1
79
80bb8:
81  fence seq_cst
82  ret void
83}
84
85define i32 @main() nounwind {
86; <label>:0
87  call void @llvm.memset.p0i8.i64(i8* bitcast ([1024 x i32]* @A to i8*), i8 0, i64 4096, i32 1, i1 false)
88  call void @llvm.memset.p0i8.i64(i8* bitcast ([1024 x i32]* @B to i8*), i8 0, i64 4096, i32 1, i1 false)
89  call void @loop_with_condition()
90  br label %1
91
92; <label>:1                                       ; preds = %8, %0
93  %indvar1 = phi i64 [ %indvar.next2, %8 ], [ 0, %0 ] ; <i64> [#uses=3]
94  %scevgep3 = getelementptr [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvar1 ; <i32*> [#uses=1]
95  %i.0 = trunc i64 %indvar1 to i32                ; <i32> [#uses=1]
96  %2 = icmp slt i32 %i.0, 1024                    ; <i1> [#uses=1]
97  br i1 %2, label %3, label %9
98
99; <label>:3                                       ; preds = %1
100  %4 = load i32, i32* %scevgep3                        ; <i32> [#uses=1]
101  %5 = icmp ne i32 %4, 3                          ; <i1> [#uses=1]
102  br i1 %5, label %6, label %7
103
104; <label>:6                                       ; preds = %3
105  br label %28
106
107; <label>:7                                       ; preds = %3
108  br label %8
109
110; <label>:8                                       ; preds = %7
111  %indvar.next2 = add i64 %indvar1, 1             ; <i64> [#uses=1]
112  br label %1
113
114; <label>:9                                       ; preds = %1
115  br label %10
116
117; <label>:10                                      ; preds = %26, %9
118  %indvar = phi i64 [ %indvar.next, %26 ], [ 0, %9 ] ; <i64> [#uses=3]
119  %scevgep = getelementptr [1024 x i32], [1024 x i32]* @A, i64 0, i64 %indvar ; <i32*> [#uses=2]
120  %i.1 = trunc i64 %indvar to i32                 ; <i32> [#uses=3]
121  %11 = icmp slt i32 %i.1, 1024                   ; <i1> [#uses=1]
122  br i1 %11, label %12, label %27
123
124; <label>:12                                      ; preds = %10
125  %13 = icmp sle i32 %i.1, 512                    ; <i1> [#uses=1]
126  br i1 %13, label %14, label %18
127
128; <label>:14                                      ; preds = %12
129  %15 = load i32, i32* %scevgep                        ; <i32> [#uses=1]
130  %16 = icmp ne i32 %15, 1                        ; <i1> [#uses=1]
131  br i1 %16, label %17, label %18
132
133; <label>:17                                      ; preds = %14
134  br label %28
135
136; <label>:18                                      ; preds = %14, %12
137  %19 = icmp sgt i32 %i.1, 512                    ; <i1> [#uses=1]
138  br i1 %19, label %20, label %24
139
140; <label>:20                                      ; preds = %18
141  %21 = load i32, i32* %scevgep                        ; <i32> [#uses=1]
142  %22 = icmp ne i32 %21, 2                        ; <i1> [#uses=1]
143  br i1 %22, label %23, label %24
144
145; <label>:23                                      ; preds = %20
146  br label %28
147
148; <label>:24                                      ; preds = %20, %18
149  br label %25
150
151; <label>:25                                      ; preds = %24
152  br label %26
153
154; <label>:26                                      ; preds = %25
155  %indvar.next = add i64 %indvar, 1               ; <i64> [#uses=1]
156  br label %10
157
158; <label>:27                                      ; preds = %10
159  br label %28
160
161; <label>:28                                      ; preds = %27, %23, %17, %6
162  %.0 = phi i32 [ 1, %6 ], [ 1, %17 ], [ 1, %23 ], [ 0, %27 ] ; <i32> [#uses=1]
163  ret i32 %.0
164}
165
166declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
167
168; CHECK: for (int c0 = 0; c0 <= 1023; c0 += 1) {
169; CHECK:   if (c0 >= 513) {
170; CHECK:     Stmt_bb5(c0);
171; CHECK:   } else
172; CHECK:     Stmt_bb4(c0);
173; CHECK:   Stmt_bb6(c0)
174; CHECK: }
175