Skip to content

Commit 9758242

Browse files
committed
[LV] Use SCEV to check if the trip count <= VF * UF.
Just comparing constant trip counts causes LV to miss cases where the vector loop body only executes once. The motivation for this is to remove the need for unrolling to remove vector loop back-edges, if the body only executes once in more cases. Reviewed By: Ayal Differential Revision: https://reviews.llvm.org/D133017
1 parent ec99bf2 commit 9758242

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,11 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
482482
Type *IdxTy =
483483
Plan.getCanonicalIV()->getStartValue()->getLiveInIRValue()->getType();
484484
const SCEV *TripCount = createTripCountSCEV(IdxTy, PSE);
485-
auto *C = dyn_cast<SCEVConstant>(TripCount);
486485
ScalarEvolution &SE = *PSE.getSE();
487-
if (!C || TripCount->isZero() ||
488-
C->getAPInt().getZExtValue() > BestVF.getKnownMinValue() * BestUF)
486+
const SCEV *C =
487+
SE.getConstant(TripCount->getType(), BestVF.getKnownMinValue() * BestUF);
488+
if (TripCount->isZero() ||
489+
!SE.isKnownPredicate(CmpInst::ICMP_ULE, TripCount, C))
489490
return;
490491

491492
LLVMContext &Ctx = SE.getContext();

llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ define void @test_tc_less_than_16(ptr %A, i64 %N) {
1111
; VF8UF1: [[CMP:%.+]] = icmp eq i64 %index.next, %n.vec
1212
; VF8UF1-NEXT: br i1 [[CMP]], label %middle.block, label %vector.body
1313
;
14-
; VF8UF2: [[CMP:%.+]] = icmp eq i64 %index.next, %n.vec
15-
; VF8UF2-NEXT: br i1 [[CMP]], label %middle.block, label %vector.body
14+
; VF8UF2: br i1 true, label %middle.block, label %vector.body
1615
;
17-
; VF16UF1: [[CMP:%.+]] = icmp eq i64 %index.next, %n.vec
18-
; VF16UF1-NEXT: br i1 [[CMP]], label %middle.block, label %vector.body
16+
; VF16UF1: br i1 true, label %middle.block, label %vector.body
1917
;
2018
entry:
2119
%and = and i64 %N, 15

0 commit comments

Comments
 (0)