[llvm] [LoopInterchange] Prevent from undoing its own transformation (PR #127473)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 18 07:55:01 PST 2025


================
@@ -1184,11 +1218,27 @@ std::optional<bool> LoopInterchangeProfitability::isProfitableForVectorization(
   return std::optional<bool>(!DepMatrix.empty());
 }
 
-bool LoopInterchangeProfitability::isProfitable(
-    const Loop *InnerLoop, const Loop *OuterLoop, unsigned InnerLoopId,
-    unsigned OuterLoopId, CharMatrix &DepMatrix,
-    const DenseMap<const Loop *, unsigned> &CostMap,
-    std::unique_ptr<CacheCost> &CC) {
+// The bubble-sort fashion algorithm is adopted to sort the loop nest, so the
+// comparison function should ideally induce a strict weak ordering required by
+// some standard C++ libraries. In particular, isProfitable should hold the
+// following properties.
+//
+// Asymmetry: If isProfitable(a, b) is true then isProfitable(b, a) is false.
----------------
kasuga-fj wrote:

What I want to argue here is that for all `f` in the three single rules (`isProfitablePerLoopCacheAnalysis`, `isProfitablePerInstrOrderCost`, or `isProfitableForVectorization`) the following property holds regardless of the current loop order

If `f(a, b)` is true, then `f(b, a)` is false (or nullopt).

This patch fixes the problem that `isProfitablePerLoopCacheAnalysis` didn't satisfy it. I believe this is the same as what you call `areLoopsInTheRightOrder`.

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


More information about the llvm-commits mailing list