[llvm] [SCEV] Try to re-use existing LCSSA phis when expanding SCEVAddRecExpr. (PR #147214)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 7 13:51:33 PDT 2025


https://github.com/fhahn commented:

> Or is the addrec expansion actually in the loop and the problem is that we currently don't support reusing expansions if they require LCSSA phi nodes due to https://github.com/fhahn/llvm-project/blob/8c8c5509e948130432d0b76ce7679a837cfa735c/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp#L1495-L1502 If that's the case, I think we should add support for that. Doesn't make sense to create a new expansion if all we need to do is (maybe) insert LCSSA phi nodes.

The expansion is outside the loop, they originate from runtime checks of another loop that uses a value out of the earlier loop.

The reason we don't have entries in the ExprValue map, is because the lcssa phi node we can re-use hasn't been visited by SCEV, so won't get added. The runtime check uses the BTC of the second loop, which will get computed w/o visiting the lcssa phi for IV + 1.

We could extend the  phi check for all expressions that are defined in a loop and used outside one, but I am not sure how we would best detect that for non-AddRec exprs?

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


More information about the llvm-commits mailing list