-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[VPlan] Extract reverse interleave pointer adjustment into VPReverseInterleavePtrRecipe #144864
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 |
---|---|---|
|
@@ -150,6 +150,7 @@ bool VPRecipeBase::mayHaveSideEffects() const { | |
case VPDerivedIVSC: | ||
case VPFirstOrderRecurrencePHISC: | ||
case VPPredInstPHISC: | ||
case VPReverseInterleavePtrSC: | ||
case VPVectorEndPointerSC: | ||
return false; | ||
case VPInstructionSC: | ||
|
@@ -2262,6 +2263,33 @@ void VPVectorPointerRecipe::print(raw_ostream &O, const Twine &Indent, | |
} | ||
#endif | ||
|
||
void VPReverseInterleavePtrRecipe::execute(VPTransformState &State) { | ||
auto &Builder = State.Builder; | ||
Value *Ptr = State.get(getPtr(), /*IsScalar*/ true); | ||
Value *RuntimeVF = State.get(getVFValue(), /*IsScalar*/ true); | ||
Type *IndexTy = Builder.getInt32Ty(); | ||
if (RuntimeVF->getType() != IndexTy) | ||
RuntimeVF = Builder.CreateZExtOrTrunc(RuntimeVF, IndexTy); | ||
Value *Index = Builder.CreateSub(RuntimeVF, Builder.getInt32(1)); | ||
Index = Builder.CreateMul(Index, Builder.getInt32(Factor)); | ||
Index = Builder.CreateNeg(Index); | ||
Value *ReversePtr = | ||
Builder.CreateGEP(IndexedTy, Ptr, Index, "", getGEPNoWrapFlags()); | ||
|
||
State.set(this, ReversePtr, /*IsScalar*/ true); | ||
} | ||
|
||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||
void VPReverseInterleavePtrRecipe::print(raw_ostream &O, const Twine &Indent, | ||
VPSlotTracker &SlotTracker) const { | ||
O << Indent; | ||
printAsOperand(O, SlotTracker); | ||
O << " = reverse-interleave-ptr"; | ||
printFlags(O); | ||
printOperands(O, SlotTracker); | ||
} | ||
#endif | ||
|
||
void VPBlendRecipe::execute(VPTransformState &State) { | ||
assert(isNormalized() && "Expected blend to be normalized!"); | ||
// We know that all PHIs in non-header blocks are converted into | ||
|
@@ -3223,25 +3251,6 @@ void VPInterleaveRecipe::execute(VPTransformState &State) { | |
if (auto *I = dyn_cast<Instruction>(ResAddr)) | ||
State.setDebugLocFrom(I->getDebugLoc()); | ||
|
||
// 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 (Group->isReverse()) { | ||
Value *RuntimeVF = | ||
getRuntimeVF(State.Builder, State.Builder.getInt32Ty(), State.VF); | ||
Value *Index = | ||
State.Builder.CreateSub(RuntimeVF, State.Builder.getInt32(1)); | ||
Index = State.Builder.CreateMul(Index, | ||
State.Builder.getInt32(Group->getFactor())); | ||
Index = State.Builder.CreateNeg(Index); | ||
|
||
bool InBounds = false; | ||
if (auto *Gep = dyn_cast<GetElementPtrInst>(ResAddr->stripPointerCasts())) | ||
InBounds = Gep->isInBounds(); | ||
Comment on lines
-3240
to
-3241
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. @alexey-bataev @fhahn The GEPNoWrapFlags setting for reverse interleave access doesn't seem to account for tail folding by mask. Could it have the same issue as noted in VPVectorEndPointerRecipe?
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. But we should keep it for EVL tail folding, no? 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. There's no predicated form of GEP, masked or VP right? So wouldn't it be an issue for both types of tail folding 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. Well, since we're generating the canonical form of the loop, we need to drop it for any folded loop 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. I think if we've already replaced the VF operand of VPVectorEndPointerRecipe with EVL, then we should be able to restore the inbounds flag (if the underlying GEP had it originally). After all, we shouldn't be computing beyond the allocation range in that case, right? 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. I think so |
||
ResAddr = State.Builder.CreateGEP(ScalarTy, ResAddr, Index, "", InBounds); | ||
} | ||
|
||
State.setDebugLocFrom(getDebugLoc()); | ||
Value *PoisonVec = PoisonValue::get(VecTy); | ||
|
||
|
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.
Add comments to the class and the its member functions