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
78 lines
3.3 KiB
LLVM
78 lines
3.3 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt -passes=slp-vectorizer -S -mcpu=cascadelake -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
|
|
|
|
define void @foo(i1 %arg) {
|
|
; CHECK-LABEL: @foo(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: [[CONV:%.*]] = uitofp i16 0 to float
|
|
; CHECK-NEXT: [[SUB:%.*]] = fsub float 6.553500e+04, 0.000000e+00
|
|
; CHECK-NEXT: br label [[BB1:%.*]]
|
|
; CHECK: bb1:
|
|
; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x float> <float poison, float poison, float 0.000000e+00, float 0.000000e+00>, float [[SUB]], i32 0
|
|
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x float> [[TMP0]], float [[CONV]], i32 1
|
|
; CHECK-NEXT: br label [[BB2:%.*]]
|
|
; CHECK: bb2:
|
|
; CHECK-NEXT: [[TMP2:%.*]] = phi <4 x float> [ [[TMP1]], [[BB1]] ], [ [[TMP14:%.*]], [[BB3:%.*]] ]
|
|
; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr null, align 8
|
|
; CHECK-NEXT: br i1 [[ARG:%.*]], label [[BB3]], label [[BB4:%.*]]
|
|
; CHECK: bb4:
|
|
; CHECK-NEXT: [[TMP4:%.*]] = fpext <4 x float> [[TMP2]] to <4 x double>
|
|
; CHECK-NEXT: [[CONV2:%.*]] = uitofp i16 0 to double
|
|
; CHECK-NEXT: [[ADD1:%.*]] = fadd double [[TMP3]], [[CONV2]]
|
|
; CHECK-NEXT: [[SUB1:%.*]] = fsub double 0.000000e+00, 0.000000e+00
|
|
; CHECK-NEXT: [[TMP5:%.*]] = insertelement <4 x double> <double poison, double poison, double 0.000000e+00, double 0.000000e+00>, double [[SUB1]], i32 0
|
|
; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x double> [[TMP5]], double [[ADD1]], i32 1
|
|
; CHECK-NEXT: [[TMP11:%.*]] = fcmp ogt <4 x double> [[TMP10]], [[TMP4]]
|
|
; CHECK-NEXT: [[TMP12:%.*]] = fptrunc <4 x double> [[TMP10]] to <4 x float>
|
|
; CHECK-NEXT: [[TMP13:%.*]] = select <4 x i1> [[TMP11]], <4 x float> [[TMP2]], <4 x float> [[TMP12]]
|
|
; CHECK-NEXT: br label [[BB3]]
|
|
; CHECK: bb3:
|
|
; CHECK-NEXT: [[TMP14]] = phi <4 x float> [ [[TMP13]], [[BB4]] ], [ [[TMP2]], [[BB2]] ]
|
|
; CHECK-NEXT: br label [[BB2]]
|
|
;
|
|
entry:
|
|
%conv = uitofp i16 zeroinitializer to float
|
|
%sub = fsub float 6.553500e+04, zeroinitializer
|
|
br label %bb1
|
|
|
|
bb1:
|
|
br label %bb2
|
|
|
|
bb2:
|
|
%0 = phi float [ %sub, %bb1 ], [ %9, %bb3 ]
|
|
%1 = phi float [ %conv, %bb1 ], [ %10, %bb3 ]
|
|
%2 = phi float [ zeroinitializer, %bb1 ], [ %11, %bb3 ]
|
|
%3 = phi float [ zeroinitializer, %bb1 ], [ %12, %bb3 ]
|
|
%4 = load double, ptr zeroinitializer, align 8
|
|
br i1 %arg, label %bb3, label %bb4
|
|
|
|
bb4:
|
|
%ext = fpext float %3 to double
|
|
%cmp1 = fcmp ogt double zeroinitializer, %ext
|
|
%5 = fptrunc double zeroinitializer to float
|
|
%sel1 = select i1 %cmp1, float %3, float %5
|
|
%ext2 = fpext float %2 to double
|
|
%cmp2 = fcmp ogt double zeroinitializer, %ext2
|
|
%6 = fptrunc double zeroinitializer to float
|
|
%sel2 = select i1 %cmp2, float %2, float %6
|
|
%ext3 = fpext float %1 to double
|
|
%conv2 = uitofp i16 zeroinitializer to double
|
|
%add1 = fadd double %4, %conv2
|
|
%cmp3 = fcmp ogt double %add1, %ext3
|
|
%7 = fptrunc double %add1 to float
|
|
%sel3 = select i1 %cmp3, float %1, float %7
|
|
%ext4 = fpext float %0 to double
|
|
%sub1 = fsub double zeroinitializer, zeroinitializer
|
|
%cmp4 = fcmp ogt double %sub1, %ext4
|
|
%8 = fptrunc double %sub1 to float
|
|
%sel4 = select i1 %cmp4, float %0, float %8
|
|
br label %bb3
|
|
|
|
bb3:
|
|
%9 = phi float [ %sel4, %bb4 ], [ %0, %bb2 ]
|
|
%10 = phi float [ %sel3, %bb4 ], [ %1, %bb2 ]
|
|
%11 = phi float [ %sel2, %bb4 ], [ %2, %bb2 ]
|
|
%12 = phi float [ %sel1, %bb4 ], [ %3, %bb2 ]
|
|
br label %bb2
|
|
}
|