Skip to content

Commit eee2e88

Browse files
committed
[LV] Add test cases with multiple exits which require versioning.
This adds some test coverage for caafdf0, which relaxed an assertion to only require a unique exit block.
1 parent eff6e75 commit eee2e88

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
; RUN: opt -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 & 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
14+
; CHECK: br
15+
;
16+
entry:
17+
br label %loop.header
18+
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
23+
24+
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
32+
33+
exit:
34+
ret void
35+
}
36+
37+
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
41+
; CHECK-NEXT: entry:
42+
; CHECK: br label %loop.header
43+
; CHECK-NOT: <2 x i32>
44+
;
45+
entry:
46+
br label %loop.header
47+
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
52+
53+
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
61+
62+
exit.0:
63+
ret i32 1
64+
65+
exit.1:
66+
ret i32 2
67+
}

0 commit comments

Comments
 (0)