[llvm] [LoopInterchange] Redundant isLexicographicallyPositive check (PR #117343)

Sjoerd Meijer via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 08:26:20 PST 2024


https://github.com/sjoerdmeijer created https://github.com/llvm/llvm-project/pull/117343

Two checks are performed to see if a direction vector is lexigraphically positive: before and after the interchange transformation. A direction vector has to be positive, so the check before transformation is more of a sanity check to see if the dependence analysis is correct, but it is redundant with the sanity check that is performed after the interchange permute.

We can't assert that the direction vector before is lexicographically positive, because the "don't know" elements are rightfully interpreted as not lexicographically positive. But if there's a "don't know" element, then the permuted direction vector will be rejected too, so the outcome is the same, so let's just skip the first check all together. 

>From 9ca92d1c6d686938cec502a1b42d97fd523ce6d8 Mon Sep 17 00:00:00 2001
From: Sjoerd Meijer <smeijer at nvidia.com>
Date: Fri, 22 Nov 2024 07:47:07 -0800
Subject: [PATCH] [LoopInterchange] Redundant isLexicographicallyPositive
 checks

Two checks are performed to see if a direction vector is lexigraphically
positive: before and after the interchange transformation. A direction
vector has to be positive, so the check before transformation is more of
a sanity check to see if the dependence analysis is correct, but it is
redundant with the sanity check that is performed after the interchange
permute, so let's just have one check.
---
 llvm/lib/Transforms/Scalar/LoopInterchange.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
index a0c0080c0bda1c..6d08535a40115f 100644
--- a/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopInterchange.cpp
@@ -204,11 +204,12 @@ static bool isLegalToInterChangeLoops(CharMatrix &DepMatrix,
   std::vector<char> Cur;
   // For each row check if it is valid to interchange.
   for (unsigned Row = 0; Row < NumRows; ++Row) {
-    // Create temporary DepVector check its lexicographical order
-    // before and after swapping OuterLoop vs InnerLoop
+    // A dependence vector has to be lexigraphically positive. We could assert
+    // that here, as a sanity check for the dependency analysis, but it can
+    // contain "don't know" elements ('*'), which will be rightfully
+    // interpreted as not lexicographical positive. So, skip that sanity check,
+    // it suffices just to check the interchanged direction vector.
     Cur = DepMatrix[Row];
-    if (!isLexicographicallyPositive(Cur))
-      return false;
     std::swap(Cur[InnerLoopId], Cur[OuterLoopId]);
     if (!isLexicographicallyPositive(Cur))
       return false;



More information about the llvm-commits mailing list