[llvm] 9758242 - [LV] Use SCEV to check if the trip count <= VF * UF.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 24 10:35:29 PST 2022


Author: Florian Hahn
Date: 2022-12-24T18:34:54Z
New Revision: 9758242046b3cdce6fb713acb6d3f5bfaa933a47

URL: https://github.com/llvm/llvm-project/commit/9758242046b3cdce6fb713acb6d3f5bfaa933a47
DIFF: https://github.com/llvm/llvm-project/commit/9758242046b3cdce6fb713acb6d3f5bfaa933a47.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
    llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 400eacf5c15b4..74067752f295e 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -482,10 +482,11 @@ void VPlanTransforms::optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
   Type *IdxTy =
       Plan.getCanonicalIV()->getStartValue()->getLiveInIRValue()->getType();
   const SCEV *TripCount = createTripCountSCEV(IdxTy, PSE);
-  auto *C = dyn_cast<SCEVConstant>(TripCount);
   ScalarEvolution &SE = *PSE.getSE();
-  if (!C || TripCount->isZero() ||
-      C->getAPInt().getZExtValue() > BestVF.getKnownMinValue() * BestUF)
+  const SCEV *C =
+      SE.getConstant(TripCount->getType(), BestVF.getKnownMinValue() * BestUF);
+  if (TripCount->isZero() ||
+      !SE.isKnownPredicate(CmpInst::ICMP_ULE, TripCount, C))
     return;
 
   LLVMContext &Ctx = SE.getContext();

diff  --git a/llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll b/llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll
index 9cb78e46b79f9..fd75177c0d106 100644
--- a/llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll
+++ b/llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll
@@ -11,11 +11,9 @@ define void @test_tc_less_than_16(ptr %A, i64 %N) {
 ; VF8UF1:       [[CMP:%.+]] = icmp eq i64 %index.next, %n.vec
 ; VF8UF1-NEXT:  br i1 [[CMP]], label %middle.block, label %vector.body
 ;
-; VF8UF2:       [[CMP:%.+]] = icmp eq i64 %index.next, %n.vec
-; VF8UF2-NEXT:  br i1 [[CMP]], label %middle.block, label %vector.body
+; VF8UF2:       br i1 true, label %middle.block, label %vector.body
 ;
-; VF16UF1:       [[CMP:%.+]] = icmp eq i64 %index.next, %n.vec
-; VF16UF1-NEXT:  br i1 [[CMP]], label %middle.block, label %vector.body
+; VF16UF1:      br i1 true, label %middle.block, label %vector.body
 ;
 entry:
   %and = and i64 %N, 15


        


More information about the llvm-commits mailing list