1; RUN: opt %loadPolly -basic-aa -polly-ast -analyze < %s | FileCheck %s 2; RUN: opt %loadPolly -basic-aa -polly-codegen -loops -analyze < %s | FileCheck %s -check-prefix=LOOPS 3 4 5;#include <string.h> 6;#define N 1024 7;int A[N]; 8;int B[N]; 9; 10;void loop_with_condition() { 11; int i; 12; 13; __sync_synchronize(); 14; for (i = 0; i < N; i++) { 15; if (i <= N / 2) { 16; if (i > 20) 17; A[i] = 1; 18; else 19; A[i] = 2; 20; } 21; B[i] = 3; 22; } 23; __sync_synchronize(); 24;} 25; 26;int main () { 27; int i; 28; 29; memset(A, 0, sizeof(int) * N); 30; memset(B, 0, sizeof(int) * N); 31; 32; loop_with_condition(); 33; 34; for (i = 0; i < N; i++) 35; if (B[i] != 3) 36; return 1; 37; 38; for (i = 0; i < N; i++) 39; if (i <= N / 2 && i > 20 && A[i] != 1) 40; return 1; 41; else if (i > N / 2) { 42; if (i <= 20 && A[i] != 2) 43; return 1; 44; if (i > 20 && A[i] != 0) 45; return 1; 46; } 47; return 0; 48;} 49 50target 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" 51 52@A = common global [1024 x i32] zeroinitializer, align 16 ; <[1024 x i32]*> [#uses=4] 53@B = common global [1024 x i32] zeroinitializer, align 16 ; <[1024 x i32]*> [#uses=4] 54 55define void @loop_with_condition() nounwind { 56bb0: 57 fence seq_cst 58 br label %bb1 59 60bb1: 61 %indvar = phi i64 [ %indvar.next, %bb10 ], [ 0, %bb0 ] ; <i64> [#uses=5] 62 %scevgep = getelementptr [1024 x i32], [1024 x i32]* @A, i64 0, i64 %indvar ; <i32*> [#uses=2] 63 %scevgep1 = getelementptr [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvar ; <i32*> [#uses=1] 64 %i.0 = trunc i64 %indvar to i32 ; <i32> [#uses=2] 65 %exitcond = icmp ne i64 %indvar, 1024 ; <i1> [#uses=1] 66 br i1 %exitcond, label %bb2, label %bb11 67 68bb2: 69 %var3 = icmp sle i32 %i.0, 512 ; <i1> [#uses=1] 70 br i1 %var3, label %bb4, label %bb9 71 72bb4: 73 %var5 = icmp sgt i32 %i.0, 20 ; <i1> [#uses=1] 74 br i1 %var5, label %bb6, label %bb7 75 76bb6: 77 store i32 1, i32* %scevgep 78 br label %bb8 79 80bb7: 81 store i32 2, i32* %scevgep 82 br label %bb8 83 84bb8: 85 br label %bb9 86 87bb9: 88 store i32 3, i32* %scevgep1 89 br label %bb10 90 91bb10: 92 %indvar.next = add i64 %indvar, 1 ; <i64> [#uses=1] 93 br label %bb1 94 95bb11: 96 fence seq_cst 97 ret void 98} 99 100define i32 @main() nounwind { 101; <label>:0 102 call void @llvm.memset.p0i8.i64(i8* bitcast ([1024 x i32]* @A to i8*), i8 0, i64 4096, i32 1, i1 false) 103 call void @llvm.memset.p0i8.i64(i8* bitcast ([1024 x i32]* @B to i8*), i8 0, i64 4096, i32 1, i1 false) 104 call void @loop_with_condition() 105 br label %1 106 107; <label>:1 ; preds = %8, %0 108 %indvar1 = phi i64 [ %indvar.next2, %8 ], [ 0, %0 ] ; <i64> [#uses=3] 109 %scevgep3 = getelementptr [1024 x i32], [1024 x i32]* @B, i64 0, i64 %indvar1 ; <i32*> [#uses=1] 110 %i.0 = trunc i64 %indvar1 to i32 ; <i32> [#uses=1] 111 %2 = icmp slt i32 %i.0, 1024 ; <i1> [#uses=1] 112 br i1 %2, label %3, label %9 113 114; <label>:3 ; preds = %1 115 %4 = load i32, i32* %scevgep3 ; <i32> [#uses=1] 116 %5 = icmp ne i32 %4, 3 ; <i1> [#uses=1] 117 br i1 %5, label %6, label %7 118 119; <label>:6 ; preds = %3 120 br label %39 121 122; <label>:7 ; preds = %3 123 br label %8 124 125; <label>:8 ; preds = %7 126 %indvar.next2 = add i64 %indvar1, 1 ; <i64> [#uses=1] 127 br label %1 128 129; <label>:9 ; preds = %1 130 br label %10 131 132; <label>:10 ; preds = %37, %9 133 %indvar = phi i64 [ %indvar.next, %37 ], [ 0, %9 ] ; <i64> [#uses=3] 134 %scevgep = getelementptr [1024 x i32], [1024 x i32]* @A, i64 0, i64 %indvar ; <i32*> [#uses=3] 135 %i.1 = trunc i64 %indvar to i32 ; <i32> [#uses=6] 136 %11 = icmp slt i32 %i.1, 1024 ; <i1> [#uses=1] 137 br i1 %11, label %12, label %38 138 139; <label>:12 ; preds = %10 140 %13 = icmp sle i32 %i.1, 512 ; <i1> [#uses=1] 141 br i1 %13, label %14, label %20 142 143; <label>:14 ; preds = %12 144 %15 = icmp sgt i32 %i.1, 20 ; <i1> [#uses=1] 145 br i1 %15, label %16, label %20 146 147; <label>:16 ; preds = %14 148 %17 = load i32, i32* %scevgep ; <i32> [#uses=1] 149 %18 = icmp ne i32 %17, 1 ; <i1> [#uses=1] 150 br i1 %18, label %19, label %20 151 152; <label>:19 ; preds = %16 153 br label %39 154 155; <label>:20 ; preds = %16, %14, %12 156 %21 = icmp sgt i32 %i.1, 512 ; <i1> [#uses=1] 157 br i1 %21, label %22, label %35 158 159; <label>:22 ; preds = %20 160 %23 = icmp sle i32 %i.1, 20 ; <i1> [#uses=1] 161 br i1 %23, label %24, label %28 162 163; <label>:24 ; preds = %22 164 %25 = load i32, i32* %scevgep ; <i32> [#uses=1] 165 %26 = icmp ne i32 %25, 2 ; <i1> [#uses=1] 166 br i1 %26, label %27, label %28 167 168; <label>:27 ; preds = %24 169 br label %39 170 171; <label>:28 ; preds = %24, %22 172 %29 = icmp sgt i32 %i.1, 20 ; <i1> [#uses=1] 173 br i1 %29, label %30, label %34 174 175; <label>:30 ; preds = %28 176 %31 = load i32, i32* %scevgep ; <i32> [#uses=1] 177 %32 = icmp ne i32 %31, 0 ; <i1> [#uses=1] 178 br i1 %32, label %33, label %34 179 180; <label>:33 ; preds = %30 181 br label %39 182 183; <label>:34 ; preds = %30, %28 184 br label %35 185 186; <label>:35 ; preds = %34, %20 187 br label %36 188 189; <label>:36 ; preds = %35 190 br label %37 191 192; <label>:37 ; preds = %36 193 %indvar.next = add i64 %indvar, 1 ; <i64> [#uses=1] 194 br label %10 195 196; <label>:38 ; preds = %10 197 br label %39 198 199; <label>:39 ; preds = %38, %33, %27, %19, %6 200 %.0 = phi i32 [ 1, %6 ], [ 1, %19 ], [ 1, %27 ], [ 1, %33 ], [ 0, %38 ] ; <i32> [#uses=1] 201 ret i32 %.0 202} 203 204declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind 205 206; CHECK: for (int c0 = 0; c0 <= 1023; c0 += 1) { 207; CHECK: if (c0 <= 20) { 208; CHECK: Stmt_bb7(c0); 209; CHECK: } else if (c0 <= 512) 210; CHECK: Stmt_bb6(c0); 211; CHECK: Stmt_bb9(c0); 212; CHECK: } 213 214; LOOPS-DAG: Loop at depth 1 containing: %bb1<header><exiting>,%bb2,%bb4,%bb7,%bb6,%bb8,%bb9,%bb10<latch> 215; LOOPS-DAG: Loop at depth 1 containing: %polly.loop_header<header>,%polly.cond,%polly.merge,%polly.then,%polly.else,%polly.stmt.bb7,%polly.cond3,%polly.merge4,%polly.then5,%polly.else6,%polly.stmt.bb6,%polly.stmt.bb9<latch><exiting> 216