-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[VPlan] Directly unroll VectorEndPointerRecipe #172372
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -783,6 +783,15 @@ static SmallVector<VPUser *> collectUsersRecursively(VPValue *V) { | |
| return Users.takeVector(); | ||
| } | ||
|
|
||
| static SmallVector<VPValue *> collectOperandsRecursively(VPRecipeBase *R) { | ||
| SetVector<VPValue *> Operands(llvm::from_range, R->operands()); | ||
| for (unsigned I = 0; I != Operands.size(); ++I) { | ||
| if (VPRecipeBase *Cur = Operands[I]->getDefiningRecipe()) | ||
| Operands.insert_range(Cur->operands()); | ||
| } | ||
| return Operands.takeVector(); | ||
| } | ||
|
|
||
| /// Scalarize a VPWidenPointerInductionRecipe by replacing it with a PtrAdd | ||
| /// (IndStart, ScalarIVSteps (0, Step)). This is used when the recipe only | ||
| /// generates scalar values. | ||
|
|
@@ -2843,11 +2852,30 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask, | |
| VPValue *Addr, *Mask, *EndPtr; | ||
|
|
||
| /// Adjust any end pointers so that they point to the end of EVL lanes not VF. | ||
| auto AdjustEndPtr = [&CurRecipe, &EVL](VPValue *EndPtr) { | ||
| auto *EVLEndPtr = cast<VPVectorEndPointerRecipe>(EndPtr)->clone(); | ||
| EVLEndPtr->insertBefore(&CurRecipe); | ||
| EVLEndPtr->setOperand(1, &EVL); | ||
| return EVLEndPtr; | ||
| auto AdjustEndPtr = [&EVL, &Plan, &TypeInfo](VPValue *EndPtr) { | ||
| auto *VEPR = cast<VPVectorEndPointerRecipe>(EndPtr); | ||
| SmallVector<VPValue *> Operands({VEPR->getOffset()}); | ||
| VPRecipeBase *OffsetR = VEPR->getOffset()->getDefiningRecipe(); | ||
| append_range(Operands, collectOperandsRecursively(OffsetR)); | ||
| for (VPValue *Op : reverse(Operands)) { | ||
| if (!Op->hasDefiningRecipe()) | ||
| continue; | ||
| VPRecipeBase *Clone = Op->getDefiningRecipe()->clone(); | ||
| Clone->insertBefore(VEPR); | ||
| VPRecipeBase *EVLR = EVL.getDefiningRecipe(); | ||
| VPBuilder Builder(EVLR->getParent(), std::next(EVLR->getIterator())); | ||
| Type *EVLType = TypeInfo.inferScalarType(&EVL); | ||
| VPValue *EVLCast = Builder.createScalarZExtOrTrunc( | ||
| &EVL, TypeInfo.inferScalarType(&Plan->getVF()), EVLType, | ||
| EVLR->getDebugLoc()); | ||
| Clone->replaceUsesOfWith(&Plan->getVF(), EVLCast); | ||
| Op->replaceUsesWithIf( | ||
| Clone->getVPSingleValue(), [&Operands](VPUser &U, unsigned Idx) { | ||
| return !is_contained(Operands, | ||
| cast<VPRecipeBase>(U).getVPSingleValue()); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's pretty unfortunate that changing the VF is a lot more complicated now. If it makes it an easier we should never have an ExplicitVectorLength with UF != 1. Maybe you can just assert here instead of trying to handle it fully generally. |
||
| } | ||
| return VEPR; | ||
| }; | ||
|
|
||
| if (match(&CurRecipe, | ||
|
|
@@ -2858,7 +2886,7 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask, | |
|
|
||
| if (match(&CurRecipe, | ||
| m_MaskedLoad(m_VPValue(EndPtr), m_RemoveMask(HeaderMask, Mask))) && | ||
| match(EndPtr, m_VecEndPtr(m_VPValue(Addr), m_Specific(&Plan->getVF()))) && | ||
| match(EndPtr, m_VecEndPtr(m_VPValue(Addr), m_VPValue())) && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to still match here for |
||
| cast<VPWidenLoadRecipe>(CurRecipe).isReverse()) | ||
| return new VPWidenLoadEVLRecipe(cast<VPWidenLoadRecipe>(CurRecipe), | ||
| AdjustEndPtr(EndPtr), EVL, Mask); | ||
|
|
@@ -2871,7 +2899,7 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask, | |
|
|
||
| if (match(&CurRecipe, m_MaskedStore(m_VPValue(EndPtr), m_VPValue(), | ||
| m_RemoveMask(HeaderMask, Mask))) && | ||
| match(EndPtr, m_VecEndPtr(m_VPValue(Addr), m_Specific(&Plan->getVF()))) && | ||
| match(EndPtr, m_VecEndPtr(m_VPValue(Addr), m_VPValue())) && | ||
| cast<VPWidenStoreRecipe>(CurRecipe).isReverse()) | ||
| return new VPWidenStoreEVLRecipe(cast<VPWidenStoreRecipe>(CurRecipe), | ||
| AdjustEndPtr(EndPtr), EVL, Mask); | ||
|
|
@@ -2916,10 +2944,10 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) { | |
| VPRegionBlock *LoopRegion = Plan.getVectorLoopRegion(); | ||
| VPBasicBlock *Header = LoopRegion->getEntryBasicBlock(); | ||
|
|
||
| assert(all_of(Plan.getVF().users(), | ||
| IsaPred<VPVectorEndPointerRecipe, VPScalarIVStepsRecipe, | ||
| VPWidenIntOrFpInductionRecipe>) && | ||
| "User of VF that we can't transform to EVL."); | ||
| assert( | ||
| all_of(Plan.getVF().users(), IsaPred<VPInstruction, VPScalarIVStepsRecipe, | ||
| VPWidenIntOrFpInductionRecipe>) && | ||
| "User of VF that we can't transform to EVL."); | ||
| Plan.getVF().replaceUsesWithIf(&EVL, [](VPUser &U, unsigned Idx) { | ||
| return isa<VPWidenIntOrFpInductionRecipe, VPScalarIVStepsRecipe>(U); | ||
| }); | ||
|
|
@@ -3412,6 +3440,7 @@ void VPlanTransforms::createInterleaveGroups( | |
| Instruction *IRInsertPos = IG->getInsertPos(); | ||
| auto *InsertPos = | ||
| cast<VPWidenMemoryRecipe>(RecipeBuilder.getRecipe(IRInsertPos)); | ||
| RecipeBuilder.setInsertPoint(InsertPos); | ||
|
|
||
| GEPNoWrapFlags NW = GEPNoWrapFlags::none(); | ||
| if (auto *Gep = dyn_cast<GetElementPtrInst>( | ||
|
|
@@ -3421,6 +3450,7 @@ void VPlanTransforms::createInterleaveGroups( | |
| // Get or create the start address for the interleave group. | ||
| VPValue *Addr = Start->getAddr(); | ||
| VPRecipeBase *AddrDef = Addr->getDefiningRecipe(); | ||
| VPBuilder &B = RecipeBuilder.getBuilder(); | ||
| if (AddrDef && !VPDT.properlyDominates(AddrDef, InsertPos)) { | ||
| // We cannot re-use the address of member zero because it does not | ||
| // dominate the insert position. Instead, use the address of the insert | ||
|
|
@@ -3436,18 +3466,17 @@ void VPlanTransforms::createInterleaveGroups( | |
| IG->getIndex(IRInsertPos), | ||
| /*IsSigned=*/true); | ||
| VPValue *OffsetVPV = Plan.getConstantInt(-Offset); | ||
| VPBuilder B(InsertPos); | ||
| Addr = B.createNoWrapPtrAdd(InsertPos->getAddr(), OffsetVPV, NW); | ||
| } | ||
| // If the group is reverse, adjust the index to refer to the last vector | ||
| // lane instead of the first. We adjust the index from the first vector | ||
| // lane, rather than directly getting the pointer for lane VF - 1, because | ||
| // the pointer operand of the interleaved access is supposed to be uniform. | ||
| if (IG->isReverse()) { | ||
| auto *ReversePtr = new VPVectorEndPointerRecipe( | ||
| Addr, &Plan.getVF(), getLoadStoreType(IRInsertPos), | ||
| -(int64_t)IG->getFactor(), NW, InsertPos->getDebugLoc()); | ||
| ReversePtr->insertBefore(InsertPos); | ||
| auto *ReversePtr = RecipeBuilder.createVectorEndPointerRecipe( | ||
| Addr, getLoadStoreType(IRInsertPos), -(int64_t)IG->getFactor(), NW, | ||
| InsertPos->getDebugLoc()); | ||
| B.insert(ReversePtr); | ||
| Addr = ReversePtr; | ||
| } | ||
| auto *VPIG = new VPInterleaveRecipe(IG, Addr, StoredValues, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this now identical to VPVectorPointerRecipe? Not for this PR but maybe can we unify them at some point.