Currently, SLP vectorizer do not care about loops and their trip count. It may lead to inefficient vectorization in some cases. Patch adds loop nest-aware tree building and cost estimation. When it comes to tree building, it now checks that tree do not span across different loop nests. The nodes from other loop nests are immediate buildvector nodes. The cost model adds the knowledge about loop trip count. If it is unknown, the default value is used, controlled by the -slp-cost-loop-min-trip-count=<value> option. The cost of the vector nodes in the loop is multiplied by the number of iteration (trip count), because each vector node will be executed the trip count number of times. This allows better cost estimation. Original Reviewers: jdenny-ornl, vporpo, hiraditya, RKSimon Original PR: https://github.com/llvm/llvm-project/pull/150450 Recommit after revert in c7bd3062f1dac975cf9b706f457b3c55b4bf57ff and in 4e500bd0015042b0cd4b7c87b81caeea06072d24 Reviewers: Pull Request: https://github.com/llvm/llvm-project/pull/187391
37 lines
1.2 KiB
LLVM
37 lines
1.2 KiB
LLVM
; REQUIRES: asserts
|
|
; RUN: opt -mtriple=systemz-unknown -mcpu=z13 -passes=slp-vectorizer -debug-only=SLP \
|
|
; RUN: -S -disable-output < %s 2>&1 | FileCheck %s
|
|
;
|
|
; Check that SLP vectorizer gets the right cost difference for a compare
|
|
; node.
|
|
|
|
; Function Attrs: norecurse nounwind readonly
|
|
define void @fun(ptr nocapture, i32 zeroext) local_unnamed_addr #0 {
|
|
.lr.ph.preheader:
|
|
br label %.lr.ph
|
|
|
|
.lr.ph: ; preds = %.lr.ph.preheader, %.lr.ph
|
|
%2 = phi i32 [ %., %.lr.ph ], [ undef, %.lr.ph.preheader ]
|
|
%3 = phi i32 [ %.9, %.lr.ph ], [ undef, %.lr.ph.preheader ]
|
|
%4 = icmp ult i32 %2, %1
|
|
%5 = select i1 %4, i32 0, i32 %1
|
|
%. = sub i32 %2, %5
|
|
%6 = icmp ult i32 %3, %1
|
|
%7 = select i1 %6, i32 0, i32 %1
|
|
%.9 = sub i32 %3, %7
|
|
%8 = zext i32 %. to i64
|
|
%9 = getelementptr inbounds i8, ptr %0, i64 %8
|
|
%10 = load i8, ptr %9, align 1
|
|
%11 = zext i32 %.9 to i64
|
|
%12 = getelementptr inbounds i8, ptr %0, i64 %11
|
|
%13 = load i8, ptr %12, align 1
|
|
%14 = icmp eq i8 %10, %13
|
|
br i1 %14, label %.lr.ph, label %._crit_edge
|
|
|
|
._crit_edge: ; preds = %.lr.ph
|
|
ret void
|
|
|
|
; CHECK: SLP: Adding cost -2 for bundle Idx: 4, n=2 [ %4 = icmp ult i32 %2, %1, ..]
|
|
}
|
|
|