@@ -737,8 +737,12 @@ ScalarEvolution::ExitLimit MustExitScalarEvolution::howManyLessThans(
737
737
//
738
738
if (!NoWrap) // THIS LINE CHANGED
739
739
return getCouldNotCompute ();
740
+ #if LLVM_VERSION_MAJOR >= 13
741
+ } else if (!Stride->isOne () && canIVOverflowOnLT (RHS, Stride, IsSigned))
742
+ #else
740
743
} else if (!Stride->isOne () &&
741
744
doesIVOverflowOnLT (RHS, Stride, IsSigned, NoWrap))
745
+ #endif
742
746
// Avoid proven overflow cases: this will ensure that the backedge taken
743
747
// count will not generate any unsigned overflow. Relaxed no-overflow
744
748
// conditions exploit NoWrapFlags, allowing to optimize in presence of
@@ -763,8 +767,13 @@ ScalarEvolution::ExitLimit MustExitScalarEvolution::howManyLessThans(
763
767
// (End-Start)/Stride times (rounded up to a multiple of Stride), where Start
764
768
// is the LHS value of the less-than comparison the first time it is evaluated
765
769
// and End is the RHS.
770
+ #if LLVM_VERSION_MAJOR >= 13
771
+ const SCEV *BECountIfBackedgeTaken =
772
+ computeBECount (getMinusSCEV (End, Start), Stride);
773
+ #else
766
774
const SCEV *BECountIfBackedgeTaken =
767
775
computeBECount (getMinusSCEV (End, Start), Stride, false );
776
+ #endif
768
777
// If the loop entry is guarded by the result of the backedge test of the
769
778
// first loop iteration, then we know the backedge will be taken at least
770
779
// once and so the backedge taken count is as above. If not then we use the
@@ -777,7 +786,11 @@ ScalarEvolution::ExitLimit MustExitScalarEvolution::howManyLessThans(
777
786
BECount = BECountIfBackedgeTaken;
778
787
else {
779
788
End = IsSigned ? getSMaxExpr (RHS, Start) : getUMaxExpr (RHS, Start);
789
+ #if LLVM_VERSION_MAJOR >= 13
790
+ BECount = computeBECount (getMinusSCEV (End, Start), Stride);
791
+ #else
780
792
BECount = computeBECount (getMinusSCEV (End, Start), Stride, false );
793
+ #endif
781
794
}
782
795
783
796
const SCEV *MaxBECount;
@@ -800,4 +813,4 @@ ScalarEvolution::ExitLimit MustExitScalarEvolution::howManyLessThans(
800
813
MaxBECount = getConstant (getUnsignedRangeMax (BECount));
801
814
802
815
return ExitLimit (BECount, MaxBECount, MaxOrZero, Predicates);
803
- }
816
+ }
0 commit comments