Question about ScalarEvolution::isMonotonicPredicateImpl

+llvm-dev +Artur Pilipenko

Hi, I hope you don’t mind if I ask you a few questions regarding SCEV.
I was reading the isLoopInvariantPredicate code to try and investigate infinite loop bug I was having and I couldn’t quite understand the logic behind isMonotonicPredicate you authored.

The loops exit cond SCEV was reported as:


(for UGT comparison with 0), which by isMonotonicPredicate logic is monotonic increasing, since there is NUW flag.

However, if I understood the definition of the monotonic predicate given in the nearby comment, it’s not the case, since after the first iteration it becomes false (!(0 > 0)), i.e. if anything it’s decreasing.
Is this correct reasoning or there is something else I’m missing?

If it is NUW then we know that after the first iteration the add rec
will produce poison (which is like undefined behavior). So for
analyzing monotonicity we can assume the containing loop only executes
iteration 0.

-- Sanjoy