1; RUN: opt %loadPolly -basic-aa -polly-ast -polly-ast-detect-parallel -analyze < %s | FileCheck %s
2
3; Verify that we actually detect this loop as the innermost loop even though
4; there is a conditional inside.
5
6; CHECK: #pragma simd
7; CHECK: for (int c0 = 0; c0 <= 1023; c0 += 1) {
8; CHECK:   if (c0 >= m + 1025) {
9; CHECK:     Stmt_if_else(c0);
10; CHECK:   } else
11; CHECK:     Stmt_if_then(c0);
12; CHECK:   Stmt_if_end(c0);
13; CHECK: }
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-n8:16:32:64"
16
17@A = common global [1024 x i32] zeroinitializer, align 16
18@B = common global [1024 x i32] zeroinitializer, align 16
19
20define void @loop_with_condition(i32 %m) nounwind {
21entry:
22  fence seq_cst
23  %tmp = sub i32 0, %m
24  %tmp1 = zext i32 %tmp to i64
25  br label %for.cond
26
27for.cond:                                         ; preds = %for.inc, %entry
28  %indvar = phi i64 [ %indvar.next, %for.inc ], [ 0, %entry ]
29  %arrayidx = getelementptr [1024 x i32], [1024 x i32]* @A, i64 0, i64 %indvar
30  %arrayidx10 = getelementptr [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvar
31  %tmp2 = add i64 %tmp1, %indvar
32  %sub = trunc i64 %tmp2 to i32
33  %exitcond = icmp ne i64 %indvar, 1024
34  br i1 %exitcond, label %for.body, label %for.end
35
36for.body:                                         ; preds = %for.cond
37  %cmp3 = icmp sle i32 %sub, 1024
38  br i1 %cmp3, label %if.then, label %if.else
39
40if.then:                                          ; preds = %for.body
41  store i32 1, i32* %arrayidx
42  br label %if.end
43
44if.else:                                          ; preds = %for.body
45  store i32 2, i32* %arrayidx
46  br label %if.end
47
48if.end:                                           ; preds = %if.else, %if.then
49  store i32 3, i32* %arrayidx10
50  br label %for.inc
51
52for.inc:                                          ; preds = %if.end
53  %indvar.next = add i64 %indvar, 1
54  br label %for.cond
55
56for.end:                                          ; preds = %for.cond
57  fence seq_cst
58  ret void
59}
60
61define i32 @main() nounwind {
62entry:
63  call void @llvm.memset.p0i8.i64(i8* bitcast ([1024 x i32]* @A to i8*), i8 0, i64 4096, i32 1, i1 false)
64  call void @llvm.memset.p0i8.i64(i8* bitcast ([1024 x i32]* @B to i8*), i8 0, i64 4096, i32 1, i1 false)
65  call void @loop_with_condition(i32 5)
66  br label %for.cond
67
68for.cond:                                         ; preds = %for.inc, %entry
69  %indvar1 = phi i64 [ %indvar.next2, %for.inc ], [ 0, %entry ]
70  %arrayidx = getelementptr [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvar1
71  %i.0 = trunc i64 %indvar1 to i32
72  %cmp = icmp slt i32 %i.0, 1024
73  br i1 %cmp, label %for.body, label %for.end
74
75for.body:                                         ; preds = %for.cond
76  %tmp3 = load i32, i32* %arrayidx
77  %cmp4 = icmp ne i32 %tmp3, 3
78  br i1 %cmp4, label %if.then, label %if.end
79
80if.then:                                          ; preds = %for.body
81  br label %return
82
83if.end:                                           ; preds = %for.body
84  br label %for.inc
85
86for.inc:                                          ; preds = %if.end
87  %indvar.next2 = add i64 %indvar1, 1
88  br label %for.cond
89
90for.end:                                          ; preds = %for.cond
91  br label %for.cond6
92
93for.cond6:                                        ; preds = %for.inc12, %for.end
94  %indvar = phi i64 [ %indvar.next, %for.inc12 ], [ 0, %for.end ]
95  %arrayidx15 = getelementptr [1024 x i32], [1024 x i32]* @A, i64 0, i64 %indvar
96  %i.1 = trunc i64 %indvar to i32
97  %cmp8 = icmp slt i32 %i.1, 1024
98  br i1 %cmp8, label %for.body9, label %for.end35
99
100for.body9:                                        ; preds = %for.cond6
101  br i1 true, label %land.lhs.true, label %if.else
102
103land.lhs.true:                                    ; preds = %for.body9
104  %tmp16 = load i32, i32* %arrayidx15
105  %cmp17 = icmp ne i32 %tmp16, 1
106  br i1 %cmp17, label %if.then18, label %if.else
107
108if.then18:                                        ; preds = %land.lhs.true
109  br label %return
110
111if.else:                                          ; preds = %land.lhs.true, %for.body9
112  br i1 false, label %land.lhs.true23, label %if.end30
113
114land.lhs.true23:                                  ; preds = %if.else
115  %tmp27 = load i32, i32* %arrayidx15
116  %cmp28 = icmp ne i32 %tmp27, 2
117  br i1 %cmp28, label %if.then29, label %if.end30
118
119if.then29:                                        ; preds = %land.lhs.true23
120  br label %return
121
122if.end30:                                         ; preds = %land.lhs.true23, %if.else
123  br label %if.end31
124
125if.end31:                                         ; preds = %if.end30
126  br label %for.inc12
127
128for.inc12:                                        ; preds = %if.end31
129  %indvar.next = add i64 %indvar, 1
130  br label %for.cond6
131
132for.end35:                                        ; preds = %for.cond6
133  br label %return
134
135return:                                           ; preds = %for.end35, %if.then29, %if.then18, %if.then
136  %retval.0 = phi i32 [ 1, %if.then ], [ 1, %if.then18 ], [ 1, %if.then29 ], [ 0, %for.end35 ]
137  ret i32 %retval.0
138}
139
140declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind
141