Files
clang-p2996/llvm/test/Transforms/LoopVectorize/multiple-exits-versioning.ll
Florian Hahn b7315ffc3c [LAA,LV] Add initial support for pointer-diff memory checks.
This patch adds initial support for a pointer diff based runtime check
scheme for vectorization. This scheme requires fewer computations and
checks than the existing full overlap checking, if it is applicable.

The main idea is to only check if source and sink of a dependency are
far enough apart so the accesses won't overlap in the vector loop. To do
so, it is sufficient to compute the difference and compare it to the
`VF * UF * AccessSize`. It is sufficient to check
`(Sink - Src) <u VF * UF * AccessSize` to rule out a backwards
dependence in the vector loop with the given VF and UF. If Src >=u Sink,
there is not dependence preventing vectorization, hence the overflow
should not matter and using the ULT should be sufficient.

Note that the initial version is restricted in multiple ways:

1. Pointers must only either be read or written, by a single
   instruction (this allows re-constructing source/sink for
   dependences with the available information)
 2. Source and sink pointers must be add-recs, with matching steps
 3. The step must be a constant.
 3. abs(step) == AccessSize.

Most of those restrictions can be relaxed in the future.

See https://github.com/llvm/llvm-project/issues/53590.

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D119078
2022-05-16 15:27:22 +01:00

68 lines
2.0 KiB
LLVM

; RUN: opt -loop-vectorize -force-vector-width=2 -S %s | FileCheck %s
; Test cases to make sure LV & loop versioning can handle loops with
; multiple exiting branches.
; Multiple branches exiting the loop to a unique exit block. The loop should
; be vectorized with versioning.
define void @multiple_exits_unique_exit_block(i32* %A, i32* %B, i64 %N) {
; CHECK-LABEL: @multiple_exits_unique_exit_block
; CHECK: vector.memcheck:
; CHECK-LABEL: vector.body:
; CHECK: %wide.load = load <2 x i32>, <2 x i32>* {{.*}}, align 4
; CHECK: store <2 x i32> %wide.load, <2 x i32>* {{.*}}, align 4
; CHECK: br
;
entry:
br label %loop.header
loop.header:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
%cond.0 = icmp eq i64 %iv, %N
br i1 %cond.0, label %exit, label %for.body
for.body:
%A.gep = getelementptr inbounds i32, i32* %A, i64 %iv
%lv = load i32, i32* %A.gep, align 4
%B.gep = getelementptr inbounds i32, i32* %B, i64 %iv
store i32 %lv, i32* %B.gep, align 4
%iv.next = add nuw i64 %iv, 1
%cond.1 = icmp ult i64 %iv.next, 1000
br i1 %cond.1, label %loop.header, label %exit
exit:
ret void
}
; Multiple branches exiting the loop to different blocks. Currently this is not supported.
define i32 @multiple_exits_multiple_exit_blocks(i32* %A, i32* %B, i64 %N) {
; CHECK-LABEL: @multiple_exits_multiple_exit_blocks
; CHECK-NEXT: entry:
; CHECK: br label %loop.header
; CHECK-NOT: <2 x i32>
;
entry:
br label %loop.header
loop.header:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
%cond.0 = icmp eq i64 %iv, %N
br i1 %cond.0, label %exit.0, label %for.body
for.body:
%A.gep = getelementptr inbounds i32, i32* %A, i64 %iv
%lv = load i32, i32* %A.gep, align 4
%B.gep = getelementptr inbounds i32, i32* %B, i64 %iv
store i32 %lv, i32* %B.gep, align 4
%iv.next = add nuw i64 %iv, 1
%cond.1 = icmp ult i64 %iv.next, 1000
br i1 %cond.1, label %loop.header, label %exit.1
exit.0:
ret i32 1
exit.1:
ret i32 2
}