[llvm] change contents of ScalarEvolution from private to protected (PR #83052)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 20 17:03:39 PDT 2024


https://github.com/efriedma-quic commented:

If I'm understanding the discussion correctly, the value the Enzyme code ultimately needs is "if the loop exits via the given edge, what was the backedge-taken count"?  This is not something we currently compute because it's not that useful for most of the transforms we care about: for example, if you're fully unrolling a loop, you need to prove the loop actually exits.  But as noted before, it's useful if you want to compute values on exit from a loop.  indvars could use it to rewrite exit values if it was available.

Given that, I don't think adding a flag to ScalarEvolution to change its behavior is the right approach.  We don't really want to to change the meaning of existing interfaces.  We just want to add a new API to BackedgeTakenInfo to ask for this info.  And then, instead of bailing out of the exit-limit computation when we can't prove the loop is finite, we just do the computation anyway, and mark the computation as "only valid if the loop actually exits via this edge" in the BackedgeTakenInfo.  So only the new API returns the computed result.

The resulting modifications look pretty similar: instead of making AssumeLoopFinite skip checks that would bail out, just make those checks set a boolean in the returned BackedgeTakenInfo.

In this approach, you shouldn't need GuaranteedUnreachable, I think; the "unreachable" edges would still be there, but they wouldn't block relevant computations.

------

I suspect just pretending the other exits don't exist could lead to subtly wrong results in ScalarEvolution::howManyLessThans, when it sets nowrap flags on some generated expressions.

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


More information about the llvm-commits mailing list