-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[VPlan] Use pointer to member 0 as VPInterleaveRecipe's pointer arg. #106431
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
Changes from all commits
ea52fe4
f23772b
5ad888a
d2fd005
3c896cb
0f2bdc0
e7c09a9
3f64c75
0b10868
45a5ea1
8a3cd0e
a361393
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 |
---|---|---|
|
@@ -1590,14 +1590,19 @@ void VPlanTransforms::dropPoisonGeneratingRecipes( | |
} | ||
|
||
void VPlanTransforms::createInterleaveGroups( | ||
const SmallPtrSetImpl<const InterleaveGroup<Instruction> *> &InterleaveGroups, | ||
VPlan &Plan, | ||
const SmallPtrSetImpl<const InterleaveGroup<Instruction> *> | ||
&InterleaveGroups, | ||
VPRecipeBuilder &RecipeBuilder, bool ScalarEpilogueAllowed) { | ||
if (InterleaveGroups.empty()) | ||
return; | ||
|
||
// Interleave memory: for each Interleave Group we marked earlier as relevant | ||
// for this VPlan, replace the Recipes widening its memory instructions with a | ||
// single VPInterleaveRecipe at its insertion point. | ||
VPDominatorTree VPDT; | ||
VPDT.recalculate(Plan); | ||
for (const auto *IG : InterleaveGroups) { | ||
auto *Recipe = | ||
cast<VPWidenMemoryRecipe>(RecipeBuilder.getRecipe(IG->getInsertPos())); | ||
SmallVector<VPValue *, 4> StoredValues; | ||
for (unsigned i = 0; i < IG->getFactor(); ++i) | ||
if (auto *SI = dyn_cast_or_null<StoreInst>(IG->getMember(i))) { | ||
|
@@ -1607,9 +1612,44 @@ void VPlanTransforms::createInterleaveGroups( | |
|
||
bool NeedsMaskForGaps = | ||
IG->requiresScalarEpilogue() && !ScalarEpilogueAllowed; | ||
auto *VPIG = new VPInterleaveRecipe(IG, Recipe->getAddr(), StoredValues, | ||
Recipe->getMask(), NeedsMaskForGaps); | ||
VPIG->insertBefore(Recipe); | ||
|
||
Instruction *IRInsertPos = IG->getInsertPos(); | ||
auto *InsertPos = | ||
cast<VPWidenMemoryRecipe>(RecipeBuilder.getRecipe(IRInsertPos)); | ||
|
||
// Get or create the start address for the interleave group. | ||
auto *Start = | ||
cast<VPWidenMemoryRecipe>(RecipeBuilder.getRecipe(IG->getMember(0))); | ||
VPValue *Addr = Start->getAddr(); | ||
VPRecipeBase *AddrDef = Addr->getDefiningRecipe(); | ||
if (AddrDef && !VPDT.properlyDominates(AddrDef, InsertPos)) { | ||
// TODO: Hoist Addr's defining recipe (and any operands as needed) to | ||
// InsertPos or sink loads above zero members to join it. | ||
bool InBounds = false; | ||
if (auto *Gep = dyn_cast<GetElementPtrInst>( | ||
getLoadStorePointerOperand(IRInsertPos)->stripPointerCasts())) | ||
InBounds = Gep->isInBounds(); | ||
|
||
// We cannot re-use the address of member zero because it does not | ||
// dominate the insert position. Instead, use the address of the insert | ||
// position and create a PtrAdd adjusting it to the address of member | ||
// zero. | ||
assert(IG->getIndex(IRInsertPos) != 0 && | ||
"index of insert position shouldn't be zero"); | ||
APInt Offset(32, | ||
getLoadStoreType(IRInsertPos)->getScalarSizeInBits() / 8 * | ||
IG->getIndex(IRInsertPos), | ||
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. Worth asserting Offset or index of IRInsertPos is non zero? 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. Added assert, thanks! |
||
/*IsSigned=*/true); | ||
VPValue *OffsetVPV = Plan.getOrAddLiveIn( | ||
ConstantInt::get(IRInsertPos->getParent()->getContext(), -Offset)); | ||
VPBuilder B(InsertPos); | ||
Addr = InBounds ? B.createInBoundsPtrAdd(InsertPos->getAddr(), OffsetVPV) | ||
: B.createPtrAdd(InsertPos->getAddr(), OffsetVPV); | ||
} | ||
auto *VPIG = new VPInterleaveRecipe(IG, Addr, StoredValues, | ||
InsertPos->getMask(), NeedsMaskForGaps); | ||
VPIG->insertBefore(InsertPos); | ||
|
||
unsigned J = 0; | ||
for (unsigned i = 0; i < IG->getFactor(); ++i) | ||
if (Instruction *Member = IG->getMember(i)) { | ||
|
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.
Indeed, better keep Idx null if not needed, to refrain from generating a redundant gep with zero.
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.
Could pull in here at the cost of a number of additional test changes or land separately.
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.
Your call; generating gep with zero also causes some test discrepancies.
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.
Thanks, I'll leave it as is for now, then drop separately.
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.
Dropped in 3ec6f80