Skip to content

Commit dae91f5

Browse files
committed
[VPlan] Avoid VPTransformState::reset in fixReduction (NFCI).
There's no need to repeatedly query and reset the state for LoopExitInstDef. This removes one of the last uses of VPTransformState::reset, by use a vector to store and update the results. No other code should try to retrieve the result from State outside the fixReductionCall.
1 parent bae41ff commit dae91f5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3830,16 +3830,18 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
38303830
LoopExitInstDef = Def;
38313831
}
38323832

3833+
VectorParts RdxParts(UF);
3834+
for (unsigned Part = 0; Part < UF; ++Part)
3835+
RdxParts[Part] = State.get(LoopExitInstDef, Part);
3836+
38333837
// If the vector reduction can be performed in a smaller type, we truncate
38343838
// then extend the loop exit value to enable InstCombine to evaluate the
38353839
// entire expression in the smaller type.
38363840
if (VF.isVector() && PhiTy != RdxDesc.getRecurrenceType()) {
38373841
assert(!PhiR->isInLoop() && "Unexpected truncated inloop reduction!");
38383842
Type *RdxVecTy = VectorType::get(RdxDesc.getRecurrenceType(), VF);
38393843
Builder.SetInsertPoint(VectorLoopLatch->getTerminator());
3840-
VectorParts RdxParts(UF);
38413844
for (unsigned Part = 0; Part < UF; ++Part) {
3842-
RdxParts[Part] = State.get(LoopExitInstDef, Part);
38433845
Value *Trunc = Builder.CreateTrunc(RdxParts[Part], RdxVecTy);
38443846
Value *Extnd = RdxDesc.isSigned() ? Builder.CreateSExt(Trunc, VecTy)
38453847
: Builder.CreateZExt(Trunc, VecTy);
@@ -3851,14 +3853,12 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
38513853
}
38523854
Builder.SetInsertPoint(LoopMiddleBlock,
38533855
LoopMiddleBlock->getFirstInsertionPt());
3854-
for (unsigned Part = 0; Part < UF; ++Part) {
3856+
for (unsigned Part = 0; Part < UF; ++Part)
38553857
RdxParts[Part] = Builder.CreateTrunc(RdxParts[Part], RdxVecTy);
3856-
State.reset(LoopExitInstDef, RdxParts[Part], Part);
3857-
}
38583858
}
38593859

38603860
// Reduce all of the unrolled parts into a single vector.
3861-
Value *ReducedPartRdx = State.get(LoopExitInstDef, 0);
3861+
Value *ReducedPartRdx = RdxParts[0];
38623862
unsigned Op = RecurrenceDescriptor::getOpcode(RK);
38633863

38643864
// The middle block terminator has already been assigned a DebugLoc here (the
@@ -3870,13 +3870,13 @@ void InnerLoopVectorizer::fixReduction(VPReductionPHIRecipe *PhiR,
38703870
// accidentally cause an extra step back into the loop while debugging.
38713871
State.setDebugLocFrom(LoopMiddleBlock->getTerminator()->getDebugLoc());
38723872
if (PhiR->isOrdered())
3873-
ReducedPartRdx = State.get(LoopExitInstDef, UF - 1);
3873+
ReducedPartRdx = RdxParts[UF - 1];
38743874
else {
38753875
// Floating-point operations should have some FMF to enable the reduction.
38763876
IRBuilderBase::FastMathFlagGuard FMFG(Builder);
38773877
Builder.setFastMathFlags(RdxDesc.getFastMathFlags());
38783878
for (unsigned Part = 1; Part < UF; ++Part) {
3879-
Value *RdxPart = State.get(LoopExitInstDef, Part);
3879+
Value *RdxPart = RdxParts[Part];
38803880
if (Op != Instruction::ICmp && Op != Instruction::FCmp)
38813881
ReducedPartRdx = Builder.CreateBinOp(
38823882
(Instruction::BinaryOps)Op, RdxPart, ReducedPartRdx, "bin.rdx");

0 commit comments

Comments
 (0)