Skip to content

Commit 07a955d

Browse files
committed
!fixup address comments
1 parent 99b0484 commit 07a955d

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class VPLane {
167167

168168
static VPLane getFirstLane() { return VPLane(0, VPLane::Kind::First); }
169169

170-
static VPLane getLastLaneForVF(const ElementCount &VF, unsigned Offset = 1) {
170+
static VPLane getLaneFromEnd(const ElementCount &VF, unsigned Offset) {
171171
unsigned LaneOffset = VF.getKnownMinValue() - Offset;
172172
Kind LaneKind;
173173
if (VF.isScalable())
@@ -179,6 +179,10 @@ class VPLane {
179179
return VPLane(LaneOffset, LaneKind);
180180
}
181181

182+
static VPLane getLastLaneForVF(const ElementCount &VF) {
183+
return getLaneFromEnd(VF, 1);
184+
}
185+
182186
/// Returns a compile-time known value for the lane index and asserts if the
183187
/// lane can only be calculated at runtime.
184188
unsigned getKnownLane() const {
@@ -1182,7 +1186,7 @@ class VPInstruction : public VPRecipeWithIRFlags {
11821186
BranchOnCount,
11831187
BranchOnCond,
11841188
ComputeReductionResult,
1185-
ExtractRecurrenceResult,
1189+
ExtractFromEnd,
11861190
LogicalAnd, // Non-poison propagating logical And.
11871191
// Add an offset in bytes (second operand) to a base pointer (first
11881192
// operand). Only generates scalar values (either for the first lane only or
@@ -3659,7 +3663,7 @@ inline bool isUniformAfterVectorization(VPValue *VPV) {
36593663
return all_of(GEP->operands(), isUniformAfterVectorization);
36603664
if (auto *VPI = dyn_cast<VPInstruction>(Def))
36613665
return VPI->getOpcode() == VPInstruction::ComputeReductionResult ||
3662-
VPI->getOpcode() == VPInstruction::ExtractRecurrenceResult;
3666+
VPI->getOpcode() == VPInstruction::ExtractFromEnd;
36633667
return false;
36643668
}
36653669
} // end namespace vputils

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ bool VPRecipeBase::mayHaveSideEffects() const {
137137
case VPInstruction::Not:
138138
case VPInstruction::CalculateTripCountMinusVF:
139139
case VPInstruction::CanonicalIVIncrementForPart:
140-
case VPInstruction::ExtractRecurrenceResult:
140+
case VPInstruction::ExtractFromEnd:
141141
case VPInstruction::LogicalAnd:
142142
case VPInstruction::PtrAdd:
143143
return false;
@@ -301,7 +301,7 @@ bool VPInstruction::canGenerateScalarForFirstLane() const {
301301
case VPInstruction::CalculateTripCountMinusVF:
302302
case VPInstruction::CanonicalIVIncrementForPart:
303303
case VPInstruction::ComputeReductionResult:
304-
case VPInstruction::ExtractRecurrenceResult:
304+
case VPInstruction::ExtractFromEnd:
305305
case VPInstruction::PtrAdd:
306306
case VPInstruction::ExplicitVectorLength:
307307
return true;
@@ -560,23 +560,25 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
560560

561561
return ReducedPartRdx;
562562
}
563-
case VPInstruction::ExtractRecurrenceResult: {
563+
case VPInstruction::ExtractFromEnd: {
564564
if (Part != 0)
565565
return State.get(this, 0, /*IsScalar*/ true);
566566

567-
// Extract the second last element in the middle block for users outside the
568-
// loop.
567+
auto *CI = cast<ConstantInt>(getOperand(1)->getLiveInIRValue());
568+
unsigned Offset = CI->getZExtValue();
569+
570+
// Extract lane VF - Offset in the from the operand.
569571
Value *Res;
570572
if (State.VF.isVector()) {
571573
Res = State.get(
572574
getOperand(0),
573-
VPIteration(State.UF - 1, VPLane::getLastLaneForVF(State.VF, 2)));
575+
VPIteration(State.UF - 1, VPLane::getLaneFromEnd(State.VF, Offset)));
574576
} else {
575577
assert(State.UF > 1 && "VF and UF cannot both be 1");
576578
// When loop is unrolled without vectorizing, retrieve the value just
577579
// prior to the final unrolled value. This is analogous to the vectorized
578580
// case above: extracting the second last element when VF > 1.
579-
Res = State.get(getOperand(0), State.UF - 2);
581+
Res = State.get(getOperand(0), State.UF - Offset);
580582
}
581583
Res->setName(Name);
582584
return Res;
@@ -621,7 +623,7 @@ void VPInstruction::execute(VPTransformState &State) {
621623
bool GeneratesPerFirstLaneOnly =
622624
canGenerateScalarForFirstLane() &&
623625
(vputils::onlyFirstLaneUsed(this) ||
624-
getOpcode() == VPInstruction::ExtractRecurrenceResult ||
626+
getOpcode() == VPInstruction::ExtractFromEnd ||
625627
getOpcode() == VPInstruction::ComputeReductionResult);
626628
bool GeneratesPerAllLanes = doesGeneratePerAllLanes();
627629
for (unsigned Part = 0; Part < State.UF; ++Part) {
@@ -716,8 +718,8 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
716718
case VPInstruction::BranchOnCount:
717719
O << "branch-on-count";
718720
break;
719-
case VPInstruction::ExtractRecurrenceResult:
720-
O << "extract-recurrence-result";
721+
case VPInstruction::ExtractFromEnd:
722+
O << "extract-from-end";
721723
break;
722724
case VPInstruction::ComputeReductionResult:
723725
O << "compute-reduction-result";

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ sinkRecurrenceUsersAfterPrevious(VPFirstOrderRecurrencePHIRecipe *FOR,
802802
}
803803

804804
bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,
805-
VPBuilder &Builder) {
805+
VPBuilder &LoopBuilder) {
806806
VPDominatorTree VPDT;
807807
VPDT.recalculate(Plan);
808808

@@ -833,22 +833,26 @@ bool VPlanTransforms::adjustFixedOrderRecurrences(VPlan &Plan,
833833
// fixed-order recurrence.
834834
VPBasicBlock *InsertBlock = Previous->getParent();
835835
if (isa<VPHeaderPHIRecipe>(Previous))
836-
Builder.setInsertPoint(InsertBlock, InsertBlock->getFirstNonPhi());
836+
LoopBuilder.setInsertPoint(InsertBlock, InsertBlock->getFirstNonPhi());
837837
else
838-
Builder.setInsertPoint(InsertBlock, std::next(Previous->getIterator()));
838+
LoopBuilder.setInsertPoint(InsertBlock,
839+
std::next(Previous->getIterator()));
839840

840841
auto *RecurSplice = cast<VPInstruction>(
841-
Builder.createNaryOp(VPInstruction::FirstOrderRecurrenceSplice,
842-
{FOR, FOR->getBackedgeValue()}));
842+
LoopBuilder.createNaryOp(VPInstruction::FirstOrderRecurrenceSplice,
843+
{FOR, FOR->getBackedgeValue()}));
843844

844845
FOR->replaceAllUsesWith(RecurSplice);
845846
// Set the first operand of RecurSplice to FOR again, after replacing
846847
// all users.
847848
RecurSplice->setOperand(0, FOR);
848849

850+
Type *IntTy = Plan.getCanonicalIV()->getScalarType();
849851
auto *Result = cast<VPInstruction>(MiddleBuilder.createNaryOp(
850-
VPInstruction::ExtractRecurrenceResult, {FOR->getBackedgeValue()}, {},
851-
"vector.recur.extract.for.phi"));
852+
VPInstruction::ExtractFromEnd,
853+
{FOR->getBackedgeValue(),
854+
Plan.getOrAddLiveIn(ConstantInt::get(IntTy, 2))},
855+
{}, "vector.recur.extract.for.phi"));
852856
RecurSplice->replaceUsesWithIf(
853857
Result, [](VPUser &U, unsigned) { return isa<VPLiveOut>(&U); });
854858
}

llvm/test/Transforms/LoopVectorize/vplan-printing.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ define i16 @print_first_order_recurrence_and_result(ptr %ptr) {
911911
; CHECK-NEXT: Successor(s): middle.block
912912
; CHECK-EMPTY:
913913
; CHECK-NEXT: middle.block:
914-
; CHECK-NEXT: EMIT vp<[[FOR_RESULT:%.+]]> = extract-recurrence-result ir<%for.1.next>
914+
; CHECK-NEXT: EMIT vp<[[FOR_RESULT:%.+]]> = extract-from-end ir<%for.1.next>, ir<2>
915915
; CHECK-NEXT: No successors
916916
; CHECK-EMPTY:
917917
; CHECK-NEXT: Live-out i16 %for.1.lcssa = vp<[[FOR_RESULT]]>

0 commit comments

Comments
 (0)