Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 15 additions & 25 deletions llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,25 +391,24 @@ class LoopVectorizationLegality {

/// Returns true if the loop has an uncountable early exit, i.e. an
/// uncountable exit that isn't the latch block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to clarify there must be single edge

Suggested change
/// Returns true if the loop has an uncountable early exit, i.e. an
/// uncountable exit that isn't the latch block.
/// Returns true if the loop has exactly one uncountable early exit, i.e. an
/// uncountable exit that isn't the latch block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bool hasUncountableEarlyExit() const { return HasUncountableEarlyExit; }
bool hasUncountableEarlyExit() const { return getUncountableEdges().size(); }

/// Returns the uncountable early exiting block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the uncountable early exiting block.
/// Returns the uncountable early exiting block, if there is a single one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

BasicBlock *getUncountableEarlyExitingBlock() const {
if (!HasUncountableEarlyExit) {
assert(getUncountableExitingBlocks().empty() &&
"Expected no uncountable exiting blocks");
if (!hasUncountableEarlyExit())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: may be more compact

Suggested change
if (!hasUncountableEarlyExit())
return hasUncountableEarlyExit() ? getUncountableEdge()->first : nullptr;`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return nullptr;
}
assert(getUncountableExitingBlocks().size() == 1 &&
assert(getUncountableEdges().size() == 1 &&
"Expected only a single uncountable exiting block");
return getUncountableExitingBlocks()[0];
return getUncountableEdges()[0].first;
}

/// Returns the destination of an uncountable early exiting block.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the destination of an uncountable early exiting block.
/// Returns the destination of the uncountable early exiting block, there is a single one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

BasicBlock *getUncountableEarlyExitBlock() const {
assert(getUncountableExitBlocks().size() == 1 &&
if (!hasUncountableEarlyExit())
return nullptr;
assert(getUncountableEdges().size() == 1 &&
"Expected only a single uncountable exit block");
return getUncountableExitBlocks()[0];
return getUncountableEdges()[0].second;
}

/// Returns true if vector representation of the instruction \p I
Expand Down Expand Up @@ -463,14 +462,10 @@ class LoopVectorizationLegality {
return CountableExitingBlocks;
}

/// Returns all the exiting blocks with an uncountable exit.
const SmallVector<BasicBlock *, 4> &getUncountableExitingBlocks() const {
return UncountableExitingBlocks;
}

/// Returns all the exit blocks from uncountable exiting blocks.
SmallVector<BasicBlock *, 4> getUncountableExitBlocks() const {
return UncountableExitBlocks;
/// Returns all the loop edges that have an uncountable exit.
const SmallVector<std::pair<BasicBlock *, BasicBlock *>, 4> &
getUncountableEdges() const {
return UncountableEdges;
}

private:
Expand Down Expand Up @@ -654,18 +649,13 @@ class LoopVectorizationLegality {
/// supported.
bool StructVecCallFound = false;

/// Indicates whether this loop has an uncountable early exit, i.e. an
/// uncountable exiting block that is not the latch.
bool HasUncountableEarlyExit = false;

/// Keep track of all the countable and uncountable exiting blocks if
/// the exact backedge taken count is not computable.
SmallVector<BasicBlock *, 4> CountableExitingBlocks;
SmallVector<BasicBlock *, 4> UncountableExitingBlocks;

/// Keep track of the destinations of all uncountable exits if the
/// exact backedge taken count is not computable.
SmallVector<BasicBlock *, 4> UncountableExitBlocks;
/// Keep track of all the loop edges with uncountable exits, where each entry
/// is a pair of (Exiting, Exit) blocks.
SmallVector<std::pair<BasicBlock *, BasicBlock *>, 4> UncountableEdges;
};

} // namespace llvm
Expand Down
11 changes: 3 additions & 8 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1635,8 +1635,6 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
const SCEV *EC =
PSE.getSE()->getPredicatedExitCount(TheLoop, BB, &Predicates);
if (isa<SCEVCouldNotCompute>(EC)) {
UncountableExitingBlocks.push_back(BB);

SmallVector<BasicBlock *, 2> Succs(successors(BB));
if (Succs.size() != 2) {
reportVectorizationFailure(
Expand All @@ -1653,7 +1651,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
assert(!TheLoop->contains(Succs[1]));
ExitBlock = Succs[1];
}
UncountableExitBlocks.push_back(ExitBlock);
UncountableEdges.push_back({BB, ExitBlock});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler to exit here once we hit more than one, now that we only store one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

} else
CountableExitingBlocks.push_back(BB);
}
Expand All @@ -1664,7 +1662,7 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
Predicates.clear();

// We only support one uncountable early exit.
if (getUncountableExitingBlocks().size() != 1) {
if (getUncountableEdges().size() != 1) {
reportVectorizationFailure(
"Loop has too many uncountable exits",
"Cannot vectorize early exit loop with more than one early exit",
Expand Down Expand Up @@ -1812,7 +1810,6 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
return false;
}

HasUncountableEarlyExit = false;
if (isa<SCEVCouldNotCompute>(PSE.getBackedgeTakenCount())) {
if (TheLoop->getExitingBlock()) {
reportVectorizationFailure("Cannot vectorize uncountable loop",
Expand All @@ -1822,10 +1819,8 @@ bool LoopVectorizationLegality::canVectorize(bool UseVPlanNativePath) {
else
return false;
} else {
HasUncountableEarlyExit = true;
if (!isVectorizableEarlyExitLoop()) {
UncountableExitingBlocks.clear();
HasUncountableEarlyExit = false;
UncountableEdges.clear();
if (DoExtraAnalysis)
Result = false;
else
Expand Down
Loading