From a51810f5296c425ab16ca6d7194595ba3da0d41a Mon Sep 17 00:00:00 2001 From: Ta-Wei Tu Date: Tue, 16 Feb 2021 22:16:53 +0800 Subject: [PATCH] [NFC][LoopInterchange] Explicitly pass both `InnerLoop` and `OuterLoop` to `processLoop` This is a split patch of D96644. Explicitly pass both `InnerLoop` and `OuterLoop` to function `processLoop` to remove the need to swap elements in loop list and allow making loop list an `ArrayRef`. Also, fix inconsistent spellings of `OuterLoopId` and `Inner Loop Id` in debug log. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D96650 --- lib/Transforms/Scalar/LoopInterchange.cpp | 10 ++++------ .../LoopInterchange/interchange-flow-dep-outer.ll | 4 ++-- .../LoopInterchange/not-interchanged-loop-nest-3.ll | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Transforms/Scalar/LoopInterchange.cpp b/lib/Transforms/Scalar/LoopInterchange.cpp index d9dbc0deb42..9b3f6a08f02 100644 --- a/lib/Transforms/Scalar/LoopInterchange.cpp +++ b/lib/Transforms/Scalar/LoopInterchange.cpp @@ -516,8 +516,8 @@ struct LoopInterchange { unsigned SelecLoopId = selectLoopForInterchange(LoopList); // Move the selected loop outwards to the best possible position. for (unsigned i = SelecLoopId; i > 0; i--) { - bool Interchanged = - processLoop(LoopList, i, i - 1, LoopNestExit, DependencyMatrix); + bool Interchanged = processLoop(LoopList[i], LoopList[i - 1], i, i - 1, + LoopNestExit, DependencyMatrix); if (!Interchanged) return Changed; // Loops interchanged reflect the same in LoopList @@ -534,13 +534,11 @@ struct LoopInterchange { return Changed; } - bool processLoop(LoopVector LoopList, unsigned InnerLoopId, + bool processLoop(Loop *InnerLoop, Loop *OuterLoop, unsigned InnerLoopId, unsigned OuterLoopId, BasicBlock *LoopNestExit, std::vector> &DependencyMatrix) { - LLVM_DEBUG(dbgs() << "Processing Inner Loop Id = " << InnerLoopId + LLVM_DEBUG(dbgs() << "Processing InnerLoopId = " << InnerLoopId << " and OuterLoopId = " << OuterLoopId << "\n"); - Loop *InnerLoop = LoopList[InnerLoopId]; - Loop *OuterLoop = LoopList[OuterLoopId]; LoopInterchangeLegality LIL(OuterLoop, InnerLoop, SE, ORE); if (!LIL.canInterchangeLoops(InnerLoopId, OuterLoopId, DependencyMatrix)) { diff --git a/test/Transforms/LoopInterchange/interchange-flow-dep-outer.ll b/test/Transforms/LoopInterchange/interchange-flow-dep-outer.ll index 096eda0da1b..23f7d912ffa 100644 --- a/test/Transforms/LoopInterchange/interchange-flow-dep-outer.ll +++ b/test/Transforms/LoopInterchange/interchange-flow-dep-outer.ll @@ -21,10 +21,10 @@ target triple = "x86_64-unknown-linux-gnu" ;; fn2(T[k]); ;; } -; CHECK: Processing Inner Loop Id = 2 and OuterLoopId = 1 +; CHECK: Processing InnerLoopId = 2 and OuterLoopId = 1 ; CHECK: Loops interchanged. -; CHECK: Processing Inner Loop Id = 1 and OuterLoopId = 0 +; CHECK: Processing InnerLoopId = 1 and OuterLoopId = 0 ; CHECK: Not interchanging loops. Cannot prove legality. @T = internal global [100 x double] zeroinitializer, align 4 diff --git a/test/Transforms/LoopInterchange/not-interchanged-loop-nest-3.ll b/test/Transforms/LoopInterchange/not-interchanged-loop-nest-3.ll index 2c169f6e56a..46aa4b5b4e7 100644 --- a/test/Transforms/LoopInterchange/not-interchanged-loop-nest-3.ll +++ b/test/Transforms/LoopInterchange/not-interchanged-loop-nest-3.ll @@ -13,10 +13,10 @@ target triple = "x86_64-unknown-linux-gnu" ;; for(int k=0;k<100;k++) ;; D[i][k][j] = D[i][k][j]+t; -; CHECK: Processing Inner Loop Id = 2 and OuterLoopId = 1 +; CHECK: Processing InnerLoopId = 2 and OuterLoopId = 1 ; CHECK: Loops interchanged. -; CHECK: Processing Inner Loop Id = 1 and OuterLoopId = 0 +; CHECK: Processing InnerLoopId = 1 and OuterLoopId = 0 ; CHECK: Interchanging loops not profitable. define void @interchange_08(i32 %t){