1; RUN: opt -passes=loop-vectorize -force-vector-width=2 -S %s | FileCheck %s 2 3; Test cases to make sure LV & loop versioning can handle loops with 4; multiple exiting branches. 5 6; Multiple branches exiting the loop to a unique exit block. The loop should 7; be vectorized with versioning. 8define void @multiple_exits_unique_exit_block(ptr %A, ptr %B, i64 %N) { 9; CHECK-LABEL: @multiple_exits_unique_exit_block 10; CHECK: vector.memcheck: 11; CHECK-LABEL: vector.body: 12; CHECK: %wide.load = load <2 x i32>, ptr {{.*}}, align 4 13; CHECK: store <2 x i32> %wide.load, ptr {{.*}}, align 4 14; CHECK: br 15; 16entry: 17 br label %loop.header 18 19loop.header: 20 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ] 21 %cond.0 = icmp eq i64 %iv, %N 22 br i1 %cond.0, label %exit, label %for.body 23 24for.body: 25 %A.gep = getelementptr inbounds i32, ptr %A, i64 %iv 26 %lv = load i32, ptr %A.gep, align 4 27 %B.gep = getelementptr inbounds i32, ptr %B, i64 %iv 28 store i32 %lv, ptr %B.gep, align 4 29 %iv.next = add nuw i64 %iv, 1 30 %cond.1 = icmp ult i64 %iv.next, 1000 31 br i1 %cond.1, label %loop.header, label %exit 32 33exit: 34 ret void 35} 36 37 38; Multiple branches exiting the loop to different blocks. Currently this is not supported. 39define i32 @multiple_exits_multiple_exit_blocks(ptr %A, ptr %B, i64 %N) { 40; CHECK-LABEL: @multiple_exits_multiple_exit_blocks 41; CHECK-NEXT: entry: 42; CHECK: br label %loop.header 43; CHECK-NOT: <2 x i32> 44; 45entry: 46 br label %loop.header 47 48loop.header: 49 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ] 50 %cond.0 = icmp eq i64 %iv, %N 51 br i1 %cond.0, label %exit.0, label %for.body 52 53for.body: 54 %A.gep = getelementptr inbounds i32, ptr %A, i64 %iv 55 %lv = load i32, ptr %A.gep, align 4 56 %B.gep = getelementptr inbounds i32, ptr %B, i64 %iv 57 store i32 %lv, ptr %B.gep, align 4 58 %iv.next = add nuw i64 %iv, 1 59 %cond.1 = icmp ult i64 %iv.next, 1000 60 br i1 %cond.1, label %loop.header, label %exit.1 61 62exit.0: 63 ret i32 1 64 65exit.1: 66 ret i32 2 67} 68