[TTI] getTypeBasedIntrinsicInstrCost - add basic handling for strided load/store...
[llvm-project.git] / llvm / test / Transforms / LoopVectorize / multiple-exits-versioning.ll
blobdd48b0e4416bd66726b75b85bb707ce9c16507f9
1 ; RUN: opt -passes=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.
8 define 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
16 entry:
17   br label %loop.header
19 loop.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
24 for.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
33 exit:
34   ret void
38 ; Multiple branches exiting the loop to different blocks. Currently this is not supported.
39 define 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>
45 entry:
46   br label %loop.header
48 loop.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
53 for.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
62 exit.0:
63   ret i32 1
65 exit.1:
66   ret i32 2