Issue |
159697
|
Summary |
[LoopVectorizer] The vectorization condition for the "early exit loop" is too strict.
|
Labels |
new issue
|
Assignees |
|
Reporter |
Guo-yyds
|
For the new feature "early exit loop vectorization", the specific restrictions include that there must be **no potentially faulty loads**.
I understand this is for safety considerations, such as in the provided test ll file.
```
define i64 @same_exit_block_pre_inc_use1() {
; CHECK-LABEL: LV: Checking a loop in 'same_exit_block_pre_inc_use1'
; CHECK: LV: Found an early exit loop with symbolic max backedge taken count: 63
; CHECK-NEXT: LV: We can vectorize this loop!
; CHECK-NOT: LV: Not vectorizing
entry:
%p1 = alloca [1024 x i8]
%p2 = alloca [1024 x i8]
call void @init_mem(ptr %p1, i64 1024)
call void @init_mem(ptr %p2, i64 1024)
br label %loop
loop:
%index = phi i64 [ %index.next, %loop.inc ], [ 3, %entry ]
%arrayidx = getelementptr inbounds i8, ptr %p1, i64 %index
%ld1 = load i8, ptr %arrayidx, align 1
%arrayidx1 = getelementptr inbounds i8, ptr %p2, i64 %index
%ld2 = load i8, ptr %arrayidx1, align 1
%cmp3 = icmp eq i8 %ld1, %ld2
br i1 %cmp3, label %loop.inc, label %loop.end
loop.inc:
%index.next = add i64 %index, 1
%exitcond = icmp ne i64 %index.next, 67
br i1 %exitcond, label %loop, label %loop.end
loop.end:
%retval = phi i64 [ %index, %loop ], [ 67, %loop.inc ]
ret i64 %retval
}
```
For this example, where p1 and p2 are allocated within the function, in many cases, the array is pre-allocated and then passed in as a parameter.
I provide the following examples:
This does not meet the requirement of "no potentially faulty loads".
```
int find_v0(vector<int> &a, int target) {
for (int i = 0; i < a.size(); i++) {
if (a[i] == target) {
return i;
}
}
return -1;
}
```
It is clearly safe to read, but currently it cannot be vectorized.
I would like to know if there is a plan to complete this task by adding some annotations in a loop, so that it can be vectorized.
If not, I will try to do it.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs