-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[LV][NFC] Clean up tail-folding check for early-exit loops #133931
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 all commits
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 |
---|---|---|
|
@@ -3987,22 +3987,6 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { | |
break; | ||
} | ||
|
||
// The only loops we can vectorize without a scalar epilogue, are loops with | ||
// a bottom-test and a single exiting block. We'd have to handle the fact | ||
// that not every instruction executes on the last iteration. This will | ||
// require a lane mask which varies through the vector loop body. (TODO) | ||
if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch()) { | ||
// If there was a tail-folding hint/switch, but we can't fold the tail by | ||
// masking, fallback to a vectorization with a scalar epilogue. | ||
if (ScalarEpilogueStatus == CM_ScalarEpilogueNotNeededUsePredicate) { | ||
LLVM_DEBUG(dbgs() << "LV: Cannot fold tail by masking: vectorize with a " | ||
"scalar epilogue instead.\n"); | ||
ScalarEpilogueStatus = CM_ScalarEpilogueAllowed; | ||
return computeFeasibleMaxVF(MaxTC, UserVF, false); | ||
} | ||
return FixedScalableVFPair::getNone(); | ||
} | ||
|
||
// Now try the tail folding | ||
|
||
// Invalidate interleave groups that require an epilogue if we can't mask | ||
|
@@ -4032,14 +4016,19 @@ LoopVectorizationCostModel::computeMaxVF(ElementCount UserVF, unsigned UserIC) { | |
} | ||
|
||
auto NoScalarEpilogueNeeded = [this, &UserIC](unsigned MaxVF) { | ||
// Return false if the loop is neither a single-latch-exit loop nor an | ||
// early-exit loop as tail-folding is not supported in that case. | ||
if (TheLoop->getExitingBlock() != TheLoop->getLoopLatch() && | ||
!Legal->hasUncountableEarlyExit()) | ||
return false; | ||
unsigned MaxVFtimesIC = UserIC ? MaxVF * UserIC : MaxVF; | ||
ScalarEvolution *SE = PSE.getSE(); | ||
// Currently only loops with countable exits are vectorized, but calling | ||
// getSymbolicMaxBackedgeTakenCount allows enablement work for loops with | ||
// uncountable exits whilst also ensuring the symbolic maximum and known | ||
// back-edge taken count remain identical for loops with countable exits. | ||
// Calling getSymbolicMaxBackedgeTakenCount enables support for loops | ||
// with uncountable exits. For countable loops, the symbolic maximum must | ||
// remain identical to the known back-edge taken count. | ||
const SCEV *BackedgeTakenCount = PSE.getSymbolicMaxBackedgeTakenCount(); | ||
assert(BackedgeTakenCount == PSE.getBackedgeTakenCount() && | ||
assert((Legal->hasUncountableEarlyExit() || | ||
BackedgeTakenCount == PSE.getBackedgeTakenCount()) && | ||
Comment on lines
+4026
to
+4031
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. Are those changes still needed? 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. Yes, the changes are still required to prevent early-exit loops from triggering the assertion under |
||
"Invalid loop count"); | ||
const SCEV *ExitCount = SE->getAddExpr( | ||
BackedgeTakenCount, SE->getOne(BackedgeTakenCount->getType())); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you document what this is checking? It's not entirely obvious from just looking at the condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks!