[llvm] [LoopInterchange] Relax the legality check to accept more patterns (PR #118267)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 1 23:23:47 PST 2024


kasuga-fj wrote:

I have investigated what happens in the case of #71519 when this patch is applied, and found that there is a problem with `LoopInterchangeProfitability::isProfitable`. In the case of #71519, the following things happen:
1. First, the loop cost (a value returned by `CacheCost::getLoopCost`) is the same for the loop of `i` and `j`.
1. In the first step, `isProfitablePerLoopCacheAnalysis` returns `std::nullopt`, then `isProfitablePerInstrOrderCost` returns `true`, and finally these loops are interchanged.
1. Because LoopInterchange uses a bubble-sort fashion algorithm, it tries to interchange these loops again.
1. This time `isProfitablePerLoopCacheAnalysis` returns `true` because `InnerIndex < OuterIndex` holds.

I think we should modify LoopInterchangeProfitability and avoid to interchange the same pair of loops more than once.;

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


More information about the llvm-commits mailing list