[llvm] [VPlan] Extend licm to hoist replicate loads (PR #179506)
Andrei Elovikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 10:57:05 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();
----------------
eas wrote:
```suggestion
auto GroupContainsR = [&R](ArrayRef<VPReplicateRecipe *> Group) {
return is_contained(Group, &R);
};
auto It = find_if(MemGroups, GroupContainsR);
if (It == MemGroups.end());
return true;
assert(std::find_if(It, MemGroups.end(), GroupContainsR) == MemGroups.end()
&& ""Recipe expected to be found in exactly one MemGroup");
auto MemGroup = *It;
```
https://github.com/llvm/llvm-project/pull/179506
More information about the llvm-commits
mailing list