-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[LoopInterchange] Ignore the cost-model, force interchange if legal #148858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
db9c37e
fe979ea
5bb2158
1e8e667
6a3b3f0
82a3043
58a6efb
057d32b
b5bc6d1
1736f1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -78,6 +78,7 @@ enum class RuleTy { | |||||||||
PerLoopCacheAnalysis, | ||||||||||
PerInstrOrderCost, | ||||||||||
ForVectorization, | ||||||||||
Ignore | ||||||||||
}; | ||||||||||
|
||||||||||
} // end anonymous namespace | ||||||||||
|
@@ -106,7 +107,10 @@ static cl::list<RuleTy> Profitabilities( | |||||||||
clEnumValN(RuleTy::PerInstrOrderCost, "instorder", | ||||||||||
"Prioritize the IVs order of each instruction"), | ||||||||||
clEnumValN(RuleTy::ForVectorization, "vectorize", | ||||||||||
"Prioritize vectorization"))); | ||||||||||
"Prioritize vectorization"), | ||||||||||
clEnumValN(RuleTy::Ignore, "ignore", | ||||||||||
"Ignore profitability, force interchange (does not " | ||||||||||
"work with other options)"))); | ||||||||||
|
||||||||||
#ifndef NDEBUG | ||||||||||
static bool noDuplicateRules(ArrayRef<RuleTy> Rules) { | ||||||||||
|
@@ -1286,6 +1290,11 @@ std::optional<bool> LoopInterchangeProfitability::isProfitableForVectorization( | |||||||||
bool LoopInterchangeProfitability::isProfitable( | ||||||||||
const Loop *InnerLoop, const Loop *OuterLoop, unsigned InnerLoopId, | ||||||||||
unsigned OuterLoopId, CharMatrix &DepMatrix, CacheCostManager &CCM) { | ||||||||||
|
||||||||||
// Return true if interchange is forced. | ||||||||||
if (Profitabilities.size() == 1 && Profitabilities[0] == RuleTy::Ignore) | ||||||||||
return true; | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary if we handle |
||||||||||
// isProfitable() is structured to avoid endless loop interchange. If the | ||||||||||
// highest priority rule (isProfitablePerLoopCacheAnalysis by default) could | ||||||||||
// decide the profitability then, profitability check will stop and return the | ||||||||||
|
@@ -1311,6 +1320,11 @@ bool LoopInterchangeProfitability::isProfitable( | |||||||||
shouldInterchange = | ||||||||||
isProfitableForVectorization(InnerLoopId, OuterLoopId, DepMatrix); | ||||||||||
break; | ||||||||||
case RuleTy::Ignore: | ||||||||||
// TODO? We ignore the force option when it appears in a list, i.e. it | ||||||||||
// should occur as the only option to be effective, as mentioned in the | ||||||||||
// help. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
break; | ||||||||||
} | ||||||||||
|
||||||||||
// If this rule could determine the profitability, don't call subsequent | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
; RUN: opt < %s -passes=loop-interchange -pass-remarks-output=%t -disable-output -loop-interchange-profitabilities=ignore -S | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you please add this? It's fine to do it in another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks, I will commit this and look at that suggestion early next week. |
||
; RUN: FileCheck --input-file=%t %s | ||
|
||
; There should be no reason to interchange this, unless it is forced. | ||
; | ||
; for (int i = 0; i<1024; i++) | ||
; for (int j = 0; j<1024; j++) | ||
; A[i][j] = 42; | ||
; | ||
; CHECK: --- !Passed | ||
; CHECK-NEXT: Pass: loop-interchange | ||
; CHECK-NEXT: Name: Interchanged | ||
; CHECK-NEXT: Function: f | ||
; CHECK-NEXT: Args: | ||
; CHECK-NEXT: - String: Loop interchanged with enclosing loop. | ||
; CHECK-NEXT: ... | ||
|
||
@A = dso_local local_unnamed_addr global [1024 x [1024 x i32]] zeroinitializer, align 4 | ||
|
||
define dso_local void @f() local_unnamed_addr #0 { | ||
entry: | ||
br label %for.cond1.preheader | ||
|
||
for.cond1.preheader: | ||
%indvars.iv17 = phi i64 [ 0, %entry ], [ %indvars.iv.next18, %for.cond.cleanup3 ] | ||
br label %for.body4 | ||
|
||
for.cond.cleanup: | ||
ret void | ||
|
||
for.cond.cleanup3: | ||
%indvars.iv.next18 = add nuw nsw i64 %indvars.iv17, 1 | ||
%exitcond20.not = icmp eq i64 %indvars.iv.next18, 1024 | ||
br i1 %exitcond20.not, label %for.cond.cleanup, label %for.cond1.preheader | ||
|
||
for.body4: | ||
%indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body4 ] | ||
%arrayidx6 = getelementptr inbounds nuw [1024 x [1024 x i32]], ptr @A, i64 0, i64 %indvars.iv17, i64 %indvars.iv | ||
store i32 42, ptr %arrayidx6, align 4 | ||
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 | ||
%exitcond.not = icmp eq i64 %indvars.iv.next, 1024 | ||
br i1 %exitcond.not, label %for.cond.cleanup3, label %for.body4 | ||
} | ||
sjoerdmeijer marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.