[llvm] [VPlan] Extend cse to eliminate redundant widened loads (PR #212543)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 30 03:59:28 PDT 2026


================
@@ -2304,16 +2308,51 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
 };
 } // end anonymous namespace
 
-/// Perform a common-subexpression-elimination of VPSingleDefRecipes on the \p
-/// Plan.
+/// Perform a common-subexpression-elimination of single-def recipes on the \p
+/// Plan, also eliminating redundant widened loads within a basic block.
 void VPlanTransforms::cse(VPlan &Plan) {
   VPDominatorTree VPDT(Plan);
   DenseMap<VPSingleDefRecipe *, VPSingleDefRecipe *, VPCSEDenseMapInfo> CSEMap;
 
   ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT(
       Plan.getEntry());
   for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
-    for (VPRecipeBase &R : *VPBB) {
+    // Widened loads that can be reused within this block, cleared by any
+    // intervening store (see below).
+    SmallVector<VPWidenLoadRecipe *, 4> LoadCandidates;
+    for (VPRecipeBase &R : make_early_inc_range(*VPBB)) {
----------------
fhahn wrote:

as far as I can tell we do not have any tests with wide loads and a block in between, like separated by a replicate region

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


More information about the llvm-commits mailing list