Skip to content

Commit 8c69ebf

Browse files
committed
disable loop interchange, fusion, and unroll-and-jam on runtime assumptions
1 parent 60ba4e6 commit 8c69ebf

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

llvm/lib/Transforms/Scalar/LoopFuse.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,11 @@ struct LoopFuser {
11291129
}
11301130
}
11311131
}
1132-
return true;
1132+
SCEVUnionPredicate Assumptions = DI.getRuntimeAssumptions();
1133+
// Fail if the dependence analysis has runtime assumptions.
1134+
// FIXME: do loop versioning to keep the original loop, and transform the
1135+
// loop under the runtime assumptions.
1136+
return Assumptions.isAlwaysTrue();
11331137
}
11341138

11351139
// Returns true if the instruction \p I can be sunk to the top of the exit
@@ -1172,7 +1176,11 @@ struct LoopFuser {
11721176
}
11731177
}
11741178

1175-
return true;
1179+
SCEVUnionPredicate Assumptions = DI.getRuntimeAssumptions();
1180+
// Fail if the dependence analysis has runtime assumptions.
1181+
// FIXME: do loop versioning to keep the original loop, and transform the
1182+
// loop under the runtime assumptions.
1183+
return Assumptions.isAlwaysTrue();
11761184
}
11771185

11781186
/// Collect instructions in the \p FC1 Preheader that can be hoisted
@@ -1420,7 +1428,11 @@ struct LoopFuser {
14201428
return false;
14211429
}
14221430

1423-
return true;
1431+
SCEVUnionPredicate Assumptions = DI.getRuntimeAssumptions();
1432+
// Fail if the dependence analysis has runtime assumptions.
1433+
// FIXME: do loop versioning to keep the original loop, and transform the
1434+
// loop under the runtime assumptions.
1435+
return Assumptions.isAlwaysTrue();
14241436
}
14251437

14261438
/// Determine if two fusion candidates are adjacent in the CFG.

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
220220
}
221221
}
222222

223-
return true;
223+
SCEVUnionPredicate Assumptions = DI->getRuntimeAssumptions();
224+
// Fail if the dependence analysis has runtime assumptions.
225+
// FIXME: do loop versioning to keep the original loop, and transform the
226+
// loop under the runtime assumptions.
227+
return Assumptions.isAlwaysTrue();
224228
}
225229

226230
// A loop is moved from index 'from' to an index 'to'. Update the Dependence
@@ -1834,6 +1838,12 @@ PreservedAnalyses LoopInterchangePass::run(LoopNest &LN,
18341838
std::unique_ptr<CacheCost> CC =
18351839
CacheCost::getCacheCost(LN.getOutermostLoop(), AR, DI);
18361840

1841+
SCEVUnionPredicate Assumptions = DI.getRuntimeAssumptions();
1842+
// Early fail when the dependence analysis has runtime assumptions.
1843+
// FIXME: this could be handled by versioning the loop.
1844+
if (!Assumptions.isAlwaysTrue())
1845+
return PreservedAnalyses::all();
1846+
18371847
if (!LoopInterchange(&AR.SE, &AR.LI, &DI, &AR.DT, CC, &ORE).run(LN))
18381848
return PreservedAnalyses::all();
18391849
U.markLoopNestChanged(true);

llvm/lib/Transforms/Utils/LoopUnrollAndJam.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,12 @@ checkDependencies(Loop &Root, const BasicBlockSet &SubLoopBlocks,
800800
EarlierLoadsAndStores.append(CurrentLoadsAndStores.begin(),
801801
CurrentLoadsAndStores.end());
802802
}
803-
return true;
803+
804+
SCEVUnionPredicate Assumptions = DI.getRuntimeAssumptions();
805+
// Fail if the dependence analysis has runtime assumptions.
806+
// FIXME: do loop versioning to keep the original loop, and transform the
807+
// loop under the runtime assumptions.
808+
return Assumptions.isAlwaysTrue();
804809
}
805810

806811
static bool isEligibleLoopForm(const Loop &Root) {

0 commit comments

Comments
 (0)