From 9ca92d1c6d686938cec502a1b42d97fd523ce6d8 Mon Sep 17 00:00:00 2001 From: Sjoerd Meijer 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 a0c0080c0bda1..6d08535a40115 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 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;