[llvm] [VPlan] Extend licm to hoist replicate loads (PR #179506)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 03:12:43 PDT 2026


================
@@ -307,6 +307,30 @@ static bool cannotHoistOrSinkRecipe(const VPRecipeBase &R) {
   return RepR && RepR->getOpcode() == Instruction::Alloca;
 }
 
+/// Return true if we do not know how to (mechanically) hoist or sink a
+/// non-memory or memory recipe \p R out of a loop region.
+static bool
+cannotHoistOrSinkRecipe(VPRecipeBase &R,
+                        ArrayRef<SmallVector<VPReplicateRecipe *, 4>> MemGroups,
+                        VPBasicBlock *FirstBB, VPBasicBlock *LastBB) {
+  if (!isa<VPReplicateRecipe>(R) || !R.mayReadFromMemory())
+    return cannotHoistOrSinkRecipe(R);
+
+  auto FilteredMemGroup =
+      make_filter_range(MemGroups, [&R](ArrayRef<VPReplicateRecipe *> Group) {
+        return is_contained(Group, &R);
+      });
+  if (FilteredMemGroup.empty())
+    return true;
+  assert(std::distance(FilteredMemGroup.begin(), FilteredMemGroup.end()) == 1 &&
+         "Recipe expected to be found in exactly one MemGroup");
+  auto MemGroup = *FilteredMemGroup.begin();
+
+  // Check that the load doesn't alias with stores between FirstBB and LastBB.
+  auto MemLoc = vputils::getMemoryLocation(*MemGroup.front());
----------------
artagnon wrote:

Hm, for (minor) improvements? The point is to group by SCEV, and get the MemLoc of the leader?

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


More information about the llvm-commits mailing list