[clang] [llvm] [LV] Mask off possibly aliasing vector lanes (PR #100579)

Sam Tebbs via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 06:58:57 PDT 2024


================
@@ -2778,6 +2808,60 @@ void VPWidenPointerInductionRecipe::print(raw_ostream &O, const Twine &Indent,
 }
 #endif
 
+void VPAliasLaneMaskRecipe::execute(VPTransformState &State) {
+  IRBuilderBase Builder = State.Builder;
+  Value *SinkValue = State.get(getSinkValue(), 0, true);
+  Value *SourceValue = State.get(getSourceValue(), 0, true);
+
+  unsigned ElementSize = 0;
+  auto *ReadInsn = cast<Instruction>(SourceValue);
+  auto *ReadCast = dyn_cast<CastInst>(SourceValue);
+  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;
+        break;
+      }
+    }
+  }
+  assert(ElementSize > 0 && "Couldn't get element size from pointer");
----------------
SamTebbs33 wrote:

Thanks Graham, I've had a deeper look and `PointerDiffInfo` provides an `AccessSize` which corresponds to what we want, so I'm using that now.

https://github.com/llvm/llvm-project/pull/100579


More information about the cfe-commits mailing list