[llvm] Fix exact backedge count algorithm in Scalar-Evolution (PR #92560)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Fri May 17 09:50:36 PDT 2024


efriedma-quic wrote:

> What is the need of howManyGreaterThans, can we not reuse howManyLessThans to do the same computations?

They probably should be merged... but it's not trivial.  If you just blindly NOT both sides, the result would be correct, but probably less accurate.  Otherwise, you need to add a bunch of conditionals to track whether you're supposed to be incrementing or decrementing.

> The comment in [line 9198](https://github.com/llvm/llvm-project/blob/9b6f0735fbff4e9a51f0c76f5630be649490f6ef/llvm/lib/Analysis/ScalarEvolution.cpp#L9198) mentions that RHS cannot include boundary value. Is this still true if the RHS is an add-recurrence?

In general, if the RHS is loop-variant, the LHS can potentially wrap even if the loop isn't infinite.  I don't think restricting to add-recurrences on the RHS changes that.

https://github.com/llvm/llvm-project/pull/92560


More information about the llvm-commits mailing list