llvm-project
174 строки · 5.3 Кб
1; RUN: opt %loadNPMPolly -aa-pipeline=basic-aa '-passes=print<polly-ast>' -disable-output < %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 ; <ptr> [#uses=4]
45@B = common global [1024 x i32] zeroinitializer, align 16 ; <ptr> [#uses=4]
46
47define void @loop_with_condition() nounwind {
48bb0:
49fence seq_cst
50br label %bb1
51
52bb1:
53%indvar = phi i64 [ %indvar.next, %bb7 ], [ 0, %bb0 ] ; <i64> [#uses=5]
54%scevgep = getelementptr [1024 x i32], ptr @A, i64 0, i64 %indvar ; <ptr> [#uses=2]
55%scevgep1 = getelementptr [1024 x i32], ptr @B, i64 0, i64 %indvar ; <ptr> [#uses=1]
56%i.0 = trunc i64 %indvar to i32 ; <i32> [#uses=1]
57%exitcond = icmp ne i64 %indvar, 1024 ; <i1> [#uses=1]
58br i1 %exitcond, label %bb2, label %bb8
59
60bb2:
61%var3 = icmp sle i32 %i.0, 512 ; <i1> [#uses=1]
62br i1 %var3, label %bb4, label %bb5
63
64bb4:
65store i32 1, ptr %scevgep
66br label %bb6
67
68bb5:
69store i32 2, ptr %scevgep
70br label %bb6
71
72bb6:
73store i32 3, ptr %scevgep1
74br label %bb7
75
76bb7:
77%indvar.next = add i64 %indvar, 1 ; <i64> [#uses=1]
78br label %bb1
79
80bb8:
81fence seq_cst
82ret void
83}
84
85define i32 @main() nounwind {
86; <label>:0
87call void @llvm.memset.p0.i64(ptr @A, i8 0, i64 4096, i32 1, i1 false)
88call void @llvm.memset.p0.i64(ptr @B, i8 0, i64 4096, i32 1, i1 false)
89call void @loop_with_condition()
90br 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], ptr @B, i64 0, i64 %indvar1 ; <ptr> [#uses=1]
95%i.0 = trunc i64 %indvar1 to i32 ; <i32> [#uses=1]
96%2 = icmp slt i32 %i.0, 1024 ; <i1> [#uses=1]
97br i1 %2, label %3, label %9
98
99; <label>:3 ; preds = %1
100%4 = load i32, ptr %scevgep3 ; <i32> [#uses=1]
101%5 = icmp ne i32 %4, 3 ; <i1> [#uses=1]
102br i1 %5, label %6, label %7
103
104; <label>:6 ; preds = %3
105br label %28
106
107; <label>:7 ; preds = %3
108br label %8
109
110; <label>:8 ; preds = %7
111%indvar.next2 = add i64 %indvar1, 1 ; <i64> [#uses=1]
112br label %1
113
114; <label>:9 ; preds = %1
115br 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], ptr @A, i64 0, i64 %indvar ; <ptr> [#uses=2]
120%i.1 = trunc i64 %indvar to i32 ; <i32> [#uses=3]
121%11 = icmp slt i32 %i.1, 1024 ; <i1> [#uses=1]
122br i1 %11, label %12, label %27
123
124; <label>:12 ; preds = %10
125%13 = icmp sle i32 %i.1, 512 ; <i1> [#uses=1]
126br i1 %13, label %14, label %18
127
128; <label>:14 ; preds = %12
129%15 = load i32, ptr %scevgep ; <i32> [#uses=1]
130%16 = icmp ne i32 %15, 1 ; <i1> [#uses=1]
131br i1 %16, label %17, label %18
132
133; <label>:17 ; preds = %14
134br label %28
135
136; <label>:18 ; preds = %14, %12
137%19 = icmp sgt i32 %i.1, 512 ; <i1> [#uses=1]
138br i1 %19, label %20, label %24
139
140; <label>:20 ; preds = %18
141%21 = load i32, ptr %scevgep ; <i32> [#uses=1]
142%22 = icmp ne i32 %21, 2 ; <i1> [#uses=1]
143br i1 %22, label %23, label %24
144
145; <label>:23 ; preds = %20
146br label %28
147
148; <label>:24 ; preds = %20, %18
149br label %25
150
151; <label>:25 ; preds = %24
152br label %26
153
154; <label>:26 ; preds = %25
155%indvar.next = add i64 %indvar, 1 ; <i64> [#uses=1]
156br label %10
157
158; <label>:27 ; preds = %10
159br 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]
163ret i32 %.0
164}
165
166declare void @llvm.memset.p0.i64(ptr 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