Skip to content

LV/Legality: fix style after cursory reading (NFC) #100363

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

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
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
86 changes: 39 additions & 47 deletions llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cl::opt<bool>
HintsAllowReordering("hints-allow-reordering", cl::init(true), cl::Hidden,
cl::desc("Allow enabling loop hints to reorder "
"FP operations during vectorization."));
}
} // namespace llvm

// TODO: Move size-based thresholds out of legality checking, make cost based
// decisions instead of hard thresholds.
Expand Down Expand Up @@ -216,20 +216,19 @@ void LoopVectorizeHints::emitRemarkWithHints() const {
TheLoop->getStartLoc(),
TheLoop->getHeader())
<< "loop not vectorized: vectorization is explicitly disabled";
else {
OptimizationRemarkMissed R(LV_NAME, "MissedDetails",
TheLoop->getStartLoc(), TheLoop->getHeader());
R << "loop not vectorized";
if (Force.Value == LoopVectorizeHints::FK_Enabled) {
R << " (Force=" << NV("Force", true);
if (Width.Value != 0)
R << ", Vector Width=" << NV("VectorWidth", getWidth());
if (getInterleave() != 0)
R << ", Interleave Count=" << NV("InterleaveCount", getInterleave());
R << ")";
}
return R;

OptimizationRemarkMissed R(LV_NAME, "MissedDetails", TheLoop->getStartLoc(),
TheLoop->getHeader());
R << "loop not vectorized";
if (Force.Value == LoopVectorizeHints::FK_Enabled) {
R << " (Force=" << NV("Force", true);
if (Width.Value != 0)
R << ", Vector Width=" << NV("VectorWidth", getWidth());
if (getInterleave() != 0)
R << ", Interleave Count=" << NV("InterleaveCount", getInterleave());
R << ")";
}
return R;
});
}

Expand Down Expand Up @@ -271,8 +270,8 @@ void LoopVectorizeHints::getHintsFromMetadata() {
if (!MD || MD->getNumOperands() == 0)
continue;
S = dyn_cast<MDString>(MD->getOperand(0));
for (unsigned i = 1, ie = MD->getNumOperands(); i < ie; ++i)
Args.push_back(MD->getOperand(i));
for (unsigned Idx = 1; Idx < MD->getNumOperands(); ++Idx)
Args.push_back(MD->getOperand(Idx));
} else {
S = dyn_cast<MDString>(MDO);
assert(Args.size() == 0 && "too many arguments for MDString");
Expand Down Expand Up @@ -444,10 +443,7 @@ static bool storeToSameAddress(ScalarEvolution *SE, StoreInst *A,
return true;

// Otherwise compare address SCEVs
if (SE->getSCEV(APtr) == SE->getSCEV(BPtr))
return true;

return false;
return SE->getSCEV(APtr) == SE->getSCEV(BPtr);
}

int LoopVectorizationLegality::isConsecutivePtr(Type *AccessTy,
Expand Down Expand Up @@ -734,26 +730,21 @@ bool LoopVectorizationLegality::setupOuterLoopInductions() {
BasicBlock *Header = TheLoop->getHeader();

// Returns true if a given Phi is a supported induction.
auto isSupportedPhi = [&](PHINode &Phi) -> bool {
auto IsSupportedPhi = [&](PHINode &Phi) -> bool {
InductionDescriptor ID;
if (InductionDescriptor::isInductionPHI(&Phi, TheLoop, PSE, ID) &&
ID.getKind() == InductionDescriptor::IK_IntInduction) {
addInductionPhi(&Phi, ID, AllowedExit);
return true;
} else {
// Bail out for any Phi in the outer loop header that is not a supported
// induction.
LLVM_DEBUG(
dbgs()
<< "LV: Found unsupported PHI for outer loop vectorization.\n");
return false;
}
// Bail out for any Phi in the outer loop header that is not a supported
// induction.
LLVM_DEBUG(
dbgs() << "LV: Found unsupported PHI for outer loop vectorization.\n");
return false;
};

if (llvm::all_of(Header->phis(), isSupportedPhi))
return true;
else
return false;
return llvm::all_of(Header->phis(), IsSupportedPhi);
}

/// Checks if a function is scalarizable according to the TLI, in
Expand Down Expand Up @@ -837,13 +828,13 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
// historical vectorizer behavior after a generalization of the
// IVDescriptor code. The intent is to remove this check, but we
// have to fix issues around code quality for such loops first.
auto isDisallowedStridedPointerInduction =
[](const InductionDescriptor &ID) {
if (AllowStridedPointerIVs)
return false;
return ID.getKind() == InductionDescriptor::IK_PtrInduction &&
ID.getConstIntStepValue() == nullptr;
};
auto IsDisallowedStridedPointerInduction =
[](const InductionDescriptor &ID) {
if (AllowStridedPointerIVs)
return false;
return ID.getKind() == InductionDescriptor::IK_PtrInduction &&
ID.getConstIntStepValue() == nullptr;
};

// TODO: Instead of recording the AllowedExit, it would be good to
// record the complementary set: NotAllowedExit. These include (but may
Expand All @@ -861,7 +852,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
// of these NotAllowedExit.
InductionDescriptor ID;
if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID) &&
!isDisallowedStridedPointerInduction(ID)) {
!IsDisallowedStridedPointerInduction(ID)) {
addInductionPhi(Phi, ID, AllowedExit);
Requirements->addExactFPMathInst(ID.getExactFPMathInst());
continue;
Expand All @@ -876,7 +867,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
// As a last resort, coerce the PHI to a AddRec expression
// and re-try classifying it a an induction PHI.
if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID, true) &&
!isDisallowedStridedPointerInduction(ID)) {
!IsDisallowedStridedPointerInduction(ID)) {
addInductionPhi(Phi, ID, AllowedExit);
continue;
}
Expand Down Expand Up @@ -932,9 +923,10 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
if (CI) {
auto *SE = PSE.getSE();
Intrinsic::ID IntrinID = getVectorIntrinsicIDForCall(CI, TLI);
for (unsigned i = 0, e = CI->arg_size(); i != e; ++i)
if (isVectorIntrinsicWithScalarOpAtArg(IntrinID, i)) {
if (!SE->isLoopInvariant(PSE.getSCEV(CI->getOperand(i)), TheLoop)) {
for (unsigned Idx = 0; Idx < CI->arg_size(); ++Idx)
if (isVectorIntrinsicWithScalarOpAtArg(IntrinID, Idx)) {
if (!SE->isLoopInvariant(PSE.getSCEV(CI->getOperand(Idx)),
TheLoop)) {
reportVectorizationFailure("Found unvectorizable intrinsic",
"intrinsic instruction cannot be vectorized",
"CantVectorizeIntrinsic", ORE, TheLoop, CI);
Expand Down Expand Up @@ -1035,14 +1027,14 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
"loop induction variable could not be identified",
"NoInductionVariable", ORE, TheLoop);
return false;
} else if (!WidestIndTy) {
}
if (!WidestIndTy) {
reportVectorizationFailure("Did not find one integer induction var",
"integer loop induction variable could not be identified",
"NoIntegerInductionVariable", ORE, TheLoop);
return false;
} else {
LLVM_DEBUG(dbgs() << "LV: Did not find one integer induction var.\n");
}
LLVM_DEBUG(dbgs() << "LV: Did not find one integer induction var.\n");
}

// Now we know the widest induction type, check if our found induction
Expand Down
Loading