[llvm] [MemoryLocation] Size Scalable Masked MemOps (PR #154785)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 1 08:20:18 PDT 2025


================
@@ -150,6 +151,28 @@ MemoryLocation::getForDest(const CallBase *CB, const TargetLibraryInfo &TLI) {
   return MemoryLocation::getBeforeOrAfter(UsedV, CB->getAAMetadata());
 }
 
+// If the mask for a memory op is a get active lane mask intrinsic
+// we can possibly infer the size of memory written or read
+static std::optional<FixedVectorType *>
+getKnownTypeFromMaskedOp(Value *Mask, VectorType *Ty) {
+  using namespace llvm::PatternMatch;
+  ConstantInt *Op0, *Op1;
+  if (!match(Mask, m_Intrinsic<Intrinsic::get_active_lane_mask>(
+                       m_ConstantInt(Op0), m_ConstantInt(Op1))))
+    return std::nullopt;
+
+  uint64_t LaneMaskLo = Op0->getZExtValue();
+  uint64_t LaneMaskHi = Op1->getZExtValue();
+  if ((LaneMaskHi == 0) || (LaneMaskHi <= LaneMaskLo))
+    return std::nullopt;
+
+  uint64_t NumElts = LaneMaskHi - LaneMaskLo;
+  if (NumElts > Ty->getElementCount().getKnownMinValue())
+    return std::nullopt;
+
+  return FixedVectorType::get(Ty->getElementType(), NumElts);
----------------
MDevereau wrote:

I've added the test dead_scalable_store_fixed

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


More information about the llvm-commits mailing list