1 ; RUN: opt -loop-vectorize -force-vector-width=2 -S %s | FileCheck %s
3 ; Test cases to make sure LV & loop versioning can handle loops with
4 ; multiple exiting branches.
6 ; Multiple branches exiting the loop to a unique exit block. The loop should
7 ; be vectorized with versioning & noalias metadata should be added.
8 define void @multiple_exits_unique_exit_block(i32* %A, i32* %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>, <2 x i32>* {{.*}}, align 4, !alias.scope
13 ; CHECK: store <2 x i32> %wide.load, <2 x i32>* {{.*}}, align 4, !alias.scope
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
25 %A.gep = getelementptr inbounds i32, i32* %A, i64 %iv
26 %lv = load i32, i32* %A.gep, align 4
27 %B.gep = getelementptr inbounds i32, i32* %B, i64 %iv
28 store i32 %lv, i32* %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
38 ; Multiple branches exiting the loop to different blocks. Currently this is not supported.
39 define i32 @multiple_exits_multiple_exit_blocks(i32* %A, i32* %B, i64 %N) {
40 ; CHECK-LABEL: @multiple_exits_multiple_exit_blocks
42 ; CHECK: br label %loop.header
43 ; CHECK-NOT: <2 x i32>
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
54 %A.gep = getelementptr inbounds i32, i32* %A, i64 %iv
55 %lv = load i32, i32* %A.gep, align 4
56 %B.gep = getelementptr inbounds i32, i32* %B, i64 %iv
57 store i32 %lv, i32* %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