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

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 27 02:52:30 PDT 2025


================
@@ -150,6 +150,29 @@ MemoryLocation::getForDest(const CallBase *CB, const TargetLibraryInfo &TLI) {
   return MemoryLocation::getBeforeOrAfter(UsedV, CB->getAAMetadata());
 }
 
+static std::optional<FixedVectorType *>
+getFixedTypeFromScalableMemOp(Value *Mask, Type *Ty) {
+  auto ActiveLaneMask = dyn_cast<IntrinsicInst>(Mask);
+  if (!ActiveLaneMask ||
+      ActiveLaneMask->getIntrinsicID() != Intrinsic::get_active_lane_mask)
+    return std::nullopt;
+
+  auto ScalableTy = dyn_cast<ScalableVectorType>(Ty);
+  if (!ScalableTy)
+    return std::nullopt;
+
+  auto LaneMaskLo = dyn_cast<ConstantInt>(ActiveLaneMask->getOperand(0));
+  auto LaneMaskHi = dyn_cast<ConstantInt>(ActiveLaneMask->getOperand(1));
+  if (!LaneMaskLo || !LaneMaskHi)
+    return std::nullopt;
+
+  uint64_t NumElts = LaneMaskHi->getZExtValue() - LaneMaskLo->getZExtValue();
----------------
MDevereau wrote:

> inactive elements at the start need to be counted as well.

>From the langref for get active lane mask:

> %m[i] = icmp ult (%base + i), %n

>From this definition I interpreted that it's not possible for the first N elements to be 0 and then have following 1s - either the mask returned from this begins with a 1, is all false, or poison. If there is a range of 3 between %base and %n, the new mask size would be 3. I added the test dead_scalar_store_offset for this scenario.

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


More information about the llvm-commits mailing list