Skip to content

Commit e463b86

Browse files
author
git apple-llvm automerger
committed
Merge commit '241349fff2e1' from llvm.org/main into next
2 parents 6de2378 + 241349f commit e463b86

File tree

2 files changed

+64
-64
lines changed

2 files changed

+64
-64
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9145,70 +9145,6 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
91459145
VPlanTransforms::clearReductionWrapFlags(*Plan);
91469146
}
91479147

9148-
void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
9149-
assert(IndDesc.getKind() == InductionDescriptor::IK_PtrInduction &&
9150-
"Not a pointer induction according to InductionDescriptor!");
9151-
assert(cast<PHINode>(getUnderlyingInstr())->getType()->isPointerTy() &&
9152-
"Unexpected type.");
9153-
assert(!onlyScalarsGenerated(State.VF.isScalable()) &&
9154-
"Recipe should have been replaced");
9155-
9156-
auto *IVR = getParent()->getPlan()->getCanonicalIV();
9157-
PHINode *CanonicalIV = cast<PHINode>(State.get(IVR, 0, /*IsScalar*/ true));
9158-
Type *PhiType = IndDesc.getStep()->getType();
9159-
9160-
// Build a pointer phi
9161-
Value *ScalarStartValue = getStartValue()->getLiveInIRValue();
9162-
Type *ScStValueType = ScalarStartValue->getType();
9163-
PHINode *NewPointerPhi = PHINode::Create(ScStValueType, 2, "pointer.phi",
9164-
CanonicalIV->getIterator());
9165-
9166-
BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this);
9167-
NewPointerPhi->addIncoming(ScalarStartValue, VectorPH);
9168-
9169-
// A pointer induction, performed by using a gep
9170-
BasicBlock::iterator InductionLoc = State.Builder.GetInsertPoint();
9171-
9172-
Value *ScalarStepValue = State.get(getOperand(1), VPIteration(0, 0));
9173-
Value *RuntimeVF = getRuntimeVF(State.Builder, PhiType, State.VF);
9174-
Value *NumUnrolledElems =
9175-
State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, State.UF));
9176-
Value *InductionGEP = GetElementPtrInst::Create(
9177-
State.Builder.getInt8Ty(), NewPointerPhi,
9178-
State.Builder.CreateMul(ScalarStepValue, NumUnrolledElems), "ptr.ind",
9179-
InductionLoc);
9180-
// Add induction update using an incorrect block temporarily. The phi node
9181-
// will be fixed after VPlan execution. Note that at this point the latch
9182-
// block cannot be used, as it does not exist yet.
9183-
// TODO: Model increment value in VPlan, by turning the recipe into a
9184-
// multi-def and a subclass of VPHeaderPHIRecipe.
9185-
NewPointerPhi->addIncoming(InductionGEP, VectorPH);
9186-
9187-
// Create UF many actual address geps that use the pointer
9188-
// phi as base and a vectorized version of the step value
9189-
// (<step*0, ..., step*N>) as offset.
9190-
for (unsigned Part = 0; Part < State.UF; ++Part) {
9191-
Type *VecPhiType = VectorType::get(PhiType, State.VF);
9192-
Value *StartOffsetScalar =
9193-
State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, Part));
9194-
Value *StartOffset =
9195-
State.Builder.CreateVectorSplat(State.VF, StartOffsetScalar);
9196-
// Create a vector of consecutive numbers from zero to VF.
9197-
StartOffset = State.Builder.CreateAdd(
9198-
StartOffset, State.Builder.CreateStepVector(VecPhiType));
9199-
9200-
assert(ScalarStepValue == State.get(getOperand(1), VPIteration(Part, 0)) &&
9201-
"scalar step must be the same across all parts");
9202-
Value *GEP = State.Builder.CreateGEP(
9203-
State.Builder.getInt8Ty(), NewPointerPhi,
9204-
State.Builder.CreateMul(
9205-
StartOffset,
9206-
State.Builder.CreateVectorSplat(State.VF, ScalarStepValue),
9207-
"vector.gep"));
9208-
State.set(this, GEP, Part);
9209-
}
9210-
}
9211-
92129148
void VPDerivedIVRecipe::execute(VPTransformState &State) {
92139149
assert(!State.Instance && "VPDerivedIVRecipe being replicated.");
92149150

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,70 @@ bool VPWidenPointerInductionRecipe::onlyScalarsGenerated(bool IsScalable) {
24492449
(!IsScalable || vputils::onlyFirstLaneUsed(this));
24502450
}
24512451

2452+
void VPWidenPointerInductionRecipe::execute(VPTransformState &State) {
2453+
assert(IndDesc.getKind() == InductionDescriptor::IK_PtrInduction &&
2454+
"Not a pointer induction according to InductionDescriptor!");
2455+
assert(cast<PHINode>(getUnderlyingInstr())->getType()->isPointerTy() &&
2456+
"Unexpected type.");
2457+
assert(!onlyScalarsGenerated(State.VF.isScalable()) &&
2458+
"Recipe should have been replaced");
2459+
2460+
auto *IVR = getParent()->getPlan()->getCanonicalIV();
2461+
PHINode *CanonicalIV = cast<PHINode>(State.get(IVR, 0, /*IsScalar*/ true));
2462+
Type *PhiType = IndDesc.getStep()->getType();
2463+
2464+
// Build a pointer phi
2465+
Value *ScalarStartValue = getStartValue()->getLiveInIRValue();
2466+
Type *ScStValueType = ScalarStartValue->getType();
2467+
PHINode *NewPointerPhi = PHINode::Create(ScStValueType, 2, "pointer.phi",
2468+
CanonicalIV->getIterator());
2469+
2470+
BasicBlock *VectorPH = State.CFG.getPreheaderBBFor(this);
2471+
NewPointerPhi->addIncoming(ScalarStartValue, VectorPH);
2472+
2473+
// A pointer induction, performed by using a gep
2474+
BasicBlock::iterator InductionLoc = State.Builder.GetInsertPoint();
2475+
2476+
Value *ScalarStepValue = State.get(getOperand(1), VPIteration(0, 0));
2477+
Value *RuntimeVF = getRuntimeVF(State.Builder, PhiType, State.VF);
2478+
Value *NumUnrolledElems =
2479+
State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, State.UF));
2480+
Value *InductionGEP = GetElementPtrInst::Create(
2481+
State.Builder.getInt8Ty(), NewPointerPhi,
2482+
State.Builder.CreateMul(ScalarStepValue, NumUnrolledElems), "ptr.ind",
2483+
InductionLoc);
2484+
// Add induction update using an incorrect block temporarily. The phi node
2485+
// will be fixed after VPlan execution. Note that at this point the latch
2486+
// block cannot be used, as it does not exist yet.
2487+
// TODO: Model increment value in VPlan, by turning the recipe into a
2488+
// multi-def and a subclass of VPHeaderPHIRecipe.
2489+
NewPointerPhi->addIncoming(InductionGEP, VectorPH);
2490+
2491+
// Create UF many actual address geps that use the pointer
2492+
// phi as base and a vectorized version of the step value
2493+
// (<step*0, ..., step*N>) as offset.
2494+
for (unsigned Part = 0; Part < State.UF; ++Part) {
2495+
Type *VecPhiType = VectorType::get(PhiType, State.VF);
2496+
Value *StartOffsetScalar =
2497+
State.Builder.CreateMul(RuntimeVF, ConstantInt::get(PhiType, Part));
2498+
Value *StartOffset =
2499+
State.Builder.CreateVectorSplat(State.VF, StartOffsetScalar);
2500+
// Create a vector of consecutive numbers from zero to VF.
2501+
StartOffset = State.Builder.CreateAdd(
2502+
StartOffset, State.Builder.CreateStepVector(VecPhiType));
2503+
2504+
assert(ScalarStepValue == State.get(getOperand(1), VPIteration(Part, 0)) &&
2505+
"scalar step must be the same across all parts");
2506+
Value *GEP = State.Builder.CreateGEP(
2507+
State.Builder.getInt8Ty(), NewPointerPhi,
2508+
State.Builder.CreateMul(
2509+
StartOffset,
2510+
State.Builder.CreateVectorSplat(State.VF, ScalarStepValue),
2511+
"vector.gep"));
2512+
State.set(this, GEP, Part);
2513+
}
2514+
}
2515+
24522516
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
24532517
void VPWidenPointerInductionRecipe::print(raw_ostream &O, const Twine &Indent,
24542518
VPSlotTracker &SlotTracker) const {

0 commit comments

Comments
 (0)