forked from OSchip/llvm-project
[UnJ] Create a hasInvariantIterationCount function. NFC
Pulled out a separate function for some code that calculates if an inner loop iteration count is invariant to it's outer loop. Differential Revision: https://reviews.llvm.org/D50063 llvm-svn: 339500
This commit is contained in:
parent
b3e3477649
commit
395b80cd3c
|
@ -490,6 +490,10 @@ void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
|
|||
/// estimate can not be made.
|
||||
Optional<unsigned> getLoopEstimatedTripCount(Loop *L);
|
||||
|
||||
/// Check inner loop (L) backedge count is known to be invariant on all iterations
|
||||
/// of its outer loop. If the loop has no parent, this is trivially true.
|
||||
bool hasInvariantIterationCount(Loop *L, ScalarEvolution &SE);
|
||||
|
||||
/// Helper to consistently add the set of standard passes to a loop pass's \c
|
||||
/// AnalysisUsage.
|
||||
///
|
||||
|
|
|
@ -754,20 +754,7 @@ bool llvm::isSafeToUnrollAndJam(Loop *L, ScalarEvolution &SE, DominatorTree &DT,
|
|||
|
||||
// Check inner loop backedge count is consistent on all iterations of the
|
||||
// outer loop
|
||||
auto CheckInnerLoopIterationCountInvariant = [](Loop *SubLoop, Loop *OuterL,
|
||||
ScalarEvolution &SE) {
|
||||
BasicBlock *SubLoopLatch = SubLoop->getLoopLatch();
|
||||
const SCEV *SubLoopBECountSC = SE.getExitCount(SubLoop, SubLoopLatch);
|
||||
if (isa<SCEVCouldNotCompute>(SubLoopBECountSC) ||
|
||||
!SubLoopBECountSC->getType()->isIntegerTy())
|
||||
return false;
|
||||
ScalarEvolution::LoopDisposition LD =
|
||||
SE.getLoopDisposition(SubLoopBECountSC, OuterL);
|
||||
if (LD != ScalarEvolution::LoopInvariant)
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
if (!CheckInnerLoopIterationCountInvariant(SubLoop, L, SE)) {
|
||||
if (!hasInvariantIterationCount(SubLoop, SE)) {
|
||||
LLVM_DEBUG(dbgs() << "Won't unroll-and-jam; Inner loop iteration count is "
|
||||
"not consistent on each iteration\n");
|
||||
return false;
|
||||
|
|
|
@ -1521,6 +1521,28 @@ Optional<unsigned> llvm::getLoopEstimatedTripCount(Loop *L) {
|
|||
return (FalseVal + (TrueVal / 2)) / TrueVal;
|
||||
}
|
||||
|
||||
bool llvm::hasInvariantIterationCount(Loop *InnerLoop,
|
||||
ScalarEvolution &SE) {
|
||||
Loop *OuterL = InnerLoop->getParentLoop();
|
||||
if (!OuterL)
|
||||
return true;
|
||||
|
||||
// Get the backedge taken count for the inner loop
|
||||
BasicBlock *InnerLoopLatch = InnerLoop->getLoopLatch();
|
||||
const SCEV *InnerLoopBECountSC = SE.getExitCount(InnerLoop, InnerLoopLatch);
|
||||
if (isa<SCEVCouldNotCompute>(InnerLoopBECountSC) ||
|
||||
!InnerLoopBECountSC->getType()->isIntegerTy())
|
||||
return false;
|
||||
|
||||
// Get whether count is invariant to the outer loop
|
||||
ScalarEvolution::LoopDisposition LD =
|
||||
SE.getLoopDisposition(InnerLoopBECountSC, OuterL);
|
||||
if (LD != ScalarEvolution::LoopInvariant)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Adds a 'fast' flag to floating point operations.
|
||||
static Value *addFastMathFlag(Value *V) {
|
||||
if (isa<FPMathOperator>(V)) {
|
||||
|
|
Loading…
Reference in New Issue