Skip to content

Commit 25da8c2

Browse files
committed
[LV] Improve code using [[maybe_unused]]
1 parent c1ac87b commit 25da8c2

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6072,24 +6072,23 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,
60726072
RetTy = IntegerType::get(RetTy->getContext(), MinBWs[I]);
60736073
auto *SE = PSE.getSE();
60746074

6075-
auto HasSingleCopyAfterVectorization = [this](Instruction *I,
6076-
ElementCount VF) -> bool {
6077-
if (VF.isScalar())
6078-
return true;
6079-
6080-
auto Scalarized = InstsToScalarize.find(VF);
6081-
assert(Scalarized != InstsToScalarize.end() &&
6082-
"VF not yet analyzed for scalarization profitability");
6083-
return !Scalarized->second.count(I) &&
6084-
llvm::all_of(I->users(), [&](User *U) {
6085-
auto *UI = cast<Instruction>(U);
6086-
return !Scalarized->second.count(UI);
6087-
});
6088-
};
6089-
(void)HasSingleCopyAfterVectorization;
6090-
60916075
Type *VectorTy;
60926076
if (isScalarAfterVectorization(I, VF)) {
6077+
[[maybe_unused]] auto HasSingleCopyAfterVectorization =
6078+
[this](Instruction *I, ElementCount VF) -> bool {
6079+
if (VF.isScalar())
6080+
return true;
6081+
6082+
auto Scalarized = InstsToScalarize.find(VF);
6083+
assert(Scalarized != InstsToScalarize.end() &&
6084+
"VF not yet analyzed for scalarization profitability");
6085+
return !Scalarized->second.count(I) &&
6086+
llvm::all_of(I->users(), [&](User *U) {
6087+
auto *UI = cast<Instruction>(U);
6088+
return !Scalarized->second.count(UI);
6089+
});
6090+
};
6091+
60936092
// With the exception of GEPs and PHIs, after scalarization there should
60946093
// only be one copy of the instruction generated in the loop. This is
60956094
// because the VF is either 1, or any instructions that need scalarizing
@@ -6348,8 +6347,8 @@ LoopVectorizationCostModel::getInstructionCost(Instruction *I,
63486347
Type *ValTy = I->getOperand(0)->getType();
63496348

63506349
if (canTruncateToMinimalBitwidth(I, VF)) {
6351-
Instruction *Op0AsInstruction = dyn_cast<Instruction>(I->getOperand(0));
6352-
(void)Op0AsInstruction;
6350+
[[maybe_unused]] Instruction *Op0AsInstruction =
6351+
dyn_cast<Instruction>(I->getOperand(0));
63536352
assert((!canTruncateToMinimalBitwidth(Op0AsInstruction, VF) ||
63546353
MinBWs[I] == MinBWs[Op0AsInstruction]) &&
63556354
"if both the operand and the compare are marked for "
@@ -7283,8 +7282,8 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72837282
MainResumeValue = EpiRedHeaderPhi->getStartValue()->getUnderlyingValue();
72847283
if (RecurrenceDescriptor::isAnyOfRecurrenceKind(
72857284
RdxDesc.getRecurrenceKind())) {
7286-
Value *StartV = EpiRedResult->getOperand(1)->getLiveInIRValue();
7287-
(void)StartV;
7285+
[[maybe_unused]] Value *StartV =
7286+
EpiRedResult->getOperand(1)->getLiveInIRValue();
72887287
auto *Cmp = cast<ICmpInst>(MainResumeValue);
72897288
assert(Cmp->getPredicate() == CmpInst::ICMP_NE &&
72907289
"AnyOf expected to start with ICMP_NE");
@@ -7298,15 +7297,14 @@ static void fixReductionScalarResumeWhenVectorizingEpilog(
72987297
Value *SentinelV = EpiRedResult->getOperand(2)->getLiveInIRValue();
72997298
using namespace llvm::PatternMatch;
73007299
Value *Cmp, *OrigResumeV, *CmpOp;
7301-
bool IsExpectedPattern =
7300+
[[maybe_unused]] bool IsExpectedPattern =
73027301
match(MainResumeValue,
73037302
m_Select(m_OneUse(m_Value(Cmp)), m_Specific(SentinelV),
73047303
m_Value(OrigResumeV))) &&
73057304
(match(Cmp, m_SpecificICmp(ICmpInst::ICMP_EQ, m_Specific(OrigResumeV),
73067305
m_Value(CmpOp))) &&
73077306
((CmpOp == StartV && isGuaranteedNotToBeUndefOrPoison(CmpOp))));
73087307
assert(IsExpectedPattern && "Unexpected reduction resume pattern");
7309-
(void)IsExpectedPattern;
73107308
MainResumeValue = OrigResumeV;
73117309
}
73127310
PHINode *MainResumePhi = cast<PHINode>(MainResumeValue);
@@ -8260,10 +8258,10 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
82608258
SmallVector<VPValue *, 4> Operands(R->operands());
82618259
if (auto *PhiR = dyn_cast<VPWidenPHIRecipe>(R)) {
82628260
VPBasicBlock *Parent = PhiR->getParent();
8263-
VPRegionBlock *LoopRegionOf = Parent->getEnclosingLoopRegion();
8261+
[[maybe_unused]] VPRegionBlock *LoopRegionOf =
8262+
Parent->getEnclosingLoopRegion();
82648263
assert(LoopRegionOf && LoopRegionOf->getEntry() == Parent &&
82658264
"Non-header phis should have been handled during predication");
8266-
(void)LoopRegionOf;
82678265
auto *Phi = cast<PHINode>(R->getUnderlyingInstr());
82688266
assert(Operands.size() == 2 && "Must have 2 operands for header phis");
82698267
if ((Recipe = tryToOptimizeInductionPHI(Phi, Operands, Range)))

0 commit comments

Comments
 (0)