diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -482,10 +482,11 @@ Type *IdxTy = Plan.getCanonicalIV()->getStartValue()->getLiveInIRValue()->getType(); const SCEV *TripCount = createTripCountSCEV(IdxTy, PSE); - auto *C = dyn_cast(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 --- a/llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll +++ b/llvm/test/Transforms/LoopVectorize/vector-loop-backedge-elimination.ll @@ -11,11 +11,9 @@ ; 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