Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Next Next commit
[LoopInterchange] Ignore the cost-model, force interchange if legal
This is useful for testing purposes, to get more test coverage.
  • Loading branch information
sjoerdmeijer committed Jul 15, 2025
commit db9c37e08f5fbb4458ea87f539eae41c275a8a2e
7 changes: 6 additions & 1 deletion llvm/lib/Transforms/Scalar/LoopInterchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ static cl::opt<unsigned int> MaxMemInstrCount(
"in the dependency matrix. Higher value may lead to more interchanges "
"at the cost of compile-time"));

static cl::opt<bool> ForceLoopInterchange(
"loop-interchange-force", cl::init(false), cl::Hidden,
cl::desc("Ignore the cost model, and force interchange if it is legal"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if we call it -loop-interchange-ignore-cost-model? -force seems it covers wider scenarios.

namespace {

using LoopVector = SmallVector<Loop *, 8>;
Expand Down Expand Up @@ -599,7 +603,8 @@ struct LoopInterchange {
}
LLVM_DEBUG(dbgs() << "Loops are legal to interchange\n");
LoopInterchangeProfitability LIP(OuterLoop, InnerLoop, SE, ORE);
if (!LIP.isProfitable(InnerLoop, OuterLoop, InnerLoopId, OuterLoopId,
if (!ForceLoopInterchange &&
!LIP.isProfitable(InnerLoop, OuterLoop, InnerLoopId, OuterLoopId,
DependencyMatrix, CCM)) {
LLVM_DEBUG(dbgs() << "Interchanging loops not profitable.\n");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
; RUN: -pass-remarks-output=%t -disable-output
; RUN: FileCheck -input-file %t --check-prefix=PROFIT-CACHE %s

; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 \
; RUN: -pass-remarks-output=%t -disable-output -loop-interchange-force=true
; RUN: FileCheck -input-file %t --check-prefix=PROFIT-VEC %s
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add another test case? Interchanging the loops in this test would be beneficial in perspective of vectorizatoin (i.e., isProfitableForVectorization returns true in this case) because it makes the innermost loop vectorizable. It would be ideal to add a case where interchanging is definitely unprofitable.


; RUN: opt < %s -passes=loop-interchange -cache-line-size=64 \
; RUN: -pass-remarks-output=%t -disable-output -loop-interchange-profitabilities=vectorize,cache,instorder
; RUN: FileCheck -input-file %t --check-prefix=PROFIT-VEC %s
Expand Down
Loading