[clang] [llvm] [LV] Mask off possibly aliasing vector lanes (PR #100579)
Sam Tebbs via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 4 06:59:50 PDT 2024
================
@@ -428,6 +431,85 @@ Value *VPInstruction::generatePerPart(VPTransformState &State, unsigned Part) {
{PredTy, ScalarTC->getType()},
{VIVElem0, ScalarTC}, nullptr, Name);
}
+ case VPInstruction::AliasLaneMask: {
+ // Given a pointer A that is being stored to, and pointer B that is being
+ // read from, both with unknown lengths, create a mask that disables
+ // elements which could overlap across a loop iteration. For example, if A
+ // is X and B is X + 2 with VF being 4, only the final two elements of the
+ // loaded vector can be stored since they don't overlap with the stored
+ // vector. %b.vec = load %b ; = [s, t, u, v]
+ // [...]
+ // store %a, %b.vec ; only u and v can be stored as their addresses don't
+ // overlap with %a + (VF - 1)
+ Value *ReadPtr = State.get(getOperand(0), VPIteration(Part, 0));
+ Value *StorePtr = State.get(getOperand(1), VPIteration(Part, 0));
+ unsigned ElementSize = 0;
+
+ // We expect the operands to the alias mask to be ptrtoint. Sometimes it's
+ // an add of a ptrtoint.
+ auto *ReadInsn = cast<Instruction>(ReadPtr);
+ auto *ReadCast = dyn_cast<CastInst>(ReadPtr);
+ if (ReadInsn->getOpcode() == Instruction::Add)
+ ReadCast = dyn_cast<CastInst>(ReadInsn->getOperand(0));
+
+ if (ReadCast && ReadCast->getOpcode() == Instruction::PtrToInt) {
+ Value *Ptr = ReadCast->getOperand(0);
+ for (auto *Use : Ptr->users()) {
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(Use)) {
+ auto *EltVT = GEP->getSourceElementType();
+ if (EltVT->isArrayTy())
+ ElementSize = EltVT->getArrayElementType()->getScalarSizeInBits() *
+ EltVT->getArrayNumElements();
+ else
+ ElementSize =
+ GEP->getSourceElementType()->getScalarSizeInBits() / 8;
----------------
SamTebbs33 wrote:
I've managed to figure it out now and am using the `AccessSize` provided by `PointerDIffInfo`. Thanks for pointing out the flakiness here!
https://github.com/llvm/llvm-project/pull/100579
More information about the llvm-commits
mailing list