@@ -78,6 +78,7 @@ enum class RuleTy {
7878 PerLoopCacheAnalysis,
7979 PerInstrOrderCost,
8080 ForVectorization,
81+ Ignore
8182};
8283
8384} // end anonymous namespace
@@ -106,14 +107,20 @@ static cl::list<RuleTy> Profitabilities(
106107 clEnumValN(RuleTy::PerInstrOrderCost, " instorder" ,
107108 " Prioritize the IVs order of each instruction" ),
108109 clEnumValN(RuleTy::ForVectorization, " vectorize" ,
109- " Prioritize vectorization" )));
110+ " Prioritize vectorization" ),
111+ clEnumValN(RuleTy::Ignore, " ignore" ,
112+ " Ignore profitability, force interchange (does not "
113+ " work with other options)" )));
110114
111115#ifndef NDEBUG
112- static bool noDuplicateRules (ArrayRef<RuleTy> Rules) {
116+ static bool noDuplicateRulesAndIgnore (ArrayRef<RuleTy> Rules) {
113117 SmallSet<RuleTy, 4 > Set;
114- for (RuleTy Rule : Rules)
118+ for (RuleTy Rule : Rules) {
115119 if (!Set.insert (Rule).second )
116120 return false ;
121+ if (Rule == RuleTy::Ignore)
122+ return false ;
123+ }
117124 return true ;
118125}
119126
@@ -1357,6 +1364,13 @@ std::optional<bool> LoopInterchangeProfitability::isProfitableForVectorization(
13571364bool LoopInterchangeProfitability::isProfitable (
13581365 const Loop *InnerLoop, const Loop *OuterLoop, unsigned InnerLoopId,
13591366 unsigned OuterLoopId, CharMatrix &DepMatrix, CacheCostManager &CCM) {
1367+
1368+ // Return true if interchange is forced and the cost-model ignored.
1369+ if (Profitabilities.size () == 1 && Profitabilities[0 ] == RuleTy::Ignore)
1370+ return true ;
1371+ assert (noDuplicateRulesAndIgnore (Profitabilities) &&
1372+ " Duplicate rules and option 'ignore' are not allowed" );
1373+
13601374 // isProfitable() is structured to avoid endless loop interchange. If the
13611375 // highest priority rule (isProfitablePerLoopCacheAnalysis by default) could
13621376 // decide the profitability then, profitability check will stop and return the
@@ -1365,7 +1379,6 @@ bool LoopInterchangeProfitability::isProfitable(
13651379 // second highest priority rule (isProfitablePerInstrOrderCost by default).
13661380 // Likewise, if it failed to analysis the profitability then only, the last
13671381 // rule (isProfitableForVectorization by default) will decide.
1368- assert (noDuplicateRules (Profitabilities) && " Detect duplicate rules" );
13691382 std::optional<bool > shouldInterchange;
13701383 for (RuleTy RT : Profitabilities) {
13711384 switch (RT) {
@@ -1382,6 +1395,9 @@ bool LoopInterchangeProfitability::isProfitable(
13821395 shouldInterchange =
13831396 isProfitableForVectorization (InnerLoopId, OuterLoopId, DepMatrix);
13841397 break ;
1398+ case RuleTy::Ignore:
1399+ llvm_unreachable (" Option 'ignore' is not supported with other options" );
1400+ break ;
13851401 }
13861402
13871403 // If this rule could determine the profitability, don't call subsequent
0 commit comments