@@ -625,9 +625,15 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR, Type *Ty,
625625 //
626626
627627 const SCEV *BECount = SE ->getBackedgeTakenCount (L);
628+ #if LLVM_VERSION_MAJOR >= 23
629+ if (PreAR && any (PreAR->getNoWrapFlags (WrapType)) &&
630+ !isa<SCEVCouldNotCompute>(BECount) && SE ->isKnownPositive (BECount))
631+ return PreStart;
632+ #else
628633 if (PreAR && PreAR->getNoWrapFlags (WrapType) &&
629634 !isa<SCEVCouldNotCompute>(BECount) && SE ->isKnownPositive (BECount))
630635 return PreStart;
636+ #endif
631637
632638 // 2. Direct overflow check on the step operation's expression.
633639 unsigned BitWidth = SE ->getTypeSizeInBits (AR ->getType ());
@@ -636,7 +642,12 @@ static const SCEV *getPreStartForExtend(const SCEVAddRecExpr *AR, Type *Ty,
636642 SE ->getAddExpr ((SE ->*GetExtendExpr)(PreStart, WideTy, Depth),
637643 (SE ->*GetExtendExpr)(Step, WideTy, Depth));
638644 if ((SE ->*GetExtendExpr)(Start, WideTy, Depth) == OperandExtendedStart) {
639- if (PreAR && AR ->getNoWrapFlags (WrapType)) {
645+ #if LLVM_VERSION_MAJOR >= 23
646+ if (PreAR && any (AR ->getNoWrapFlags (WrapType)))
647+ #else
648+ if (PreAR && AR ->getNoWrapFlags (WrapType))
649+ #endif
650+ {
640651 // If we know `AR` == {`PreStart`+`Step`,+,`Step`} is `WrapType` (FlagNSW
641652 // or FlagNUW) and that `PreStart` + `Step` is `WrapType` too, then
642653 // `PreAR` == {`PreStart`,+,`Step`} is also `WrapType`. Cache this fact.
@@ -684,7 +695,7 @@ static SCEV::NoWrapFlags StrengthenNoWrapFlags(ScalarEvolution *SE,
684695 (void )CanAnalyze;
685696 assert (CanAnalyze && " don't call from other places!" );
686697
687- int SignOrUnsignMask = SCEV ::FlagNUW | SCEV ::FlagNSW;
698+ auto SignOrUnsignMask = SCEV ::FlagNUW | SCEV ::FlagNSW;
688699 SCEV ::NoWrapFlags SignOrUnsignWrap =
689700 ScalarEvolution::maskFlags (Flags, SignOrUnsignMask);
690701
@@ -843,7 +854,13 @@ ScalarEvolution::ExitLimit MustExitScalarEvolution::howManyLessThans(
843854 // implicit/exceptional) which causes the loop to execute before the
844855 // exiting instruction we're analyzing would trigger UB.
845856 auto WrapType = IsSigned ? SCEV ::FlagNSW : SCEV ::FlagNUW;
857+
858+ #if LLVM_VERSION_MAJOR >= 23
859+ bool NoWrap = ControlsExit && any (IV ->getNoWrapFlags (WrapType));
860+ #else
846861 bool NoWrap = ControlsExit && IV ->getNoWrapFlags (WrapType);
862+ #endif
863+
847864 ICmpInst::Predicate Cond = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT ;
848865
849866 const SCEV *Stride = IV ->getStepRecurrence (*this );
0 commit comments