[llvm] [VPlan] Extract reverse operation for reverse accesses (PR #146525)
    Mel Chen via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Fri Sep  5 02:14:10 PDT 2025
    
    
  
================
@@ -2339,6 +2355,39 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
       CurVPV->replaceAllUsesWith(EVLRecipe->getVPSingleValue());
     }
     ToErase.push_back(CurRecipe);
+
+    // Convert general reverse operations on loaded values and stored values
+    // into vp.reverse, when the VPVectorEndPointerRecipe adjusting the access
+    // address uses EVL instead of VF.
+    // TODO: Extend conversion along the def-use/use-def chain, as reverse
+    // operations may be eliminated or moved in the future.
+    if (auto *MemR = dyn_cast<VPWidenMemoryRecipe>(EVLRecipe);
+        MemR && match(MemR->getAddr(),
+                      m_VectorEndPointer(m_VPValue(), m_Specific(&EVL)))) {
+      assert(MemR->isReverse() &&
+             "Only reverse access uses VPVectorEndPointerRecipe as address");
+      VPRecipeBase *Candidate = nullptr;
+      if (auto *LoadR = dyn_cast<VPWidenLoadEVLRecipe>(MemR)) {
+        assert(LoadR->getNumUsers() == 1 &&
+               "Unexpected user number of reverse load");
----------------
Mel-Chen wrote:
> Maybe add a comment about why this assert should hold?
```
    if (auto *Load = dyn_cast<LoadInst>(I)) {
      auto *LoadR =
          new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse,
                                VPIRMetadata(*Load, LVer), Load->getDebugLoc());
      if (Reverse) {
        Builder.insert(LoadR);
        return new VPInstruction(VPInstruction::Reverse, LoadR,
                                 LoadR->getDebugLoc());
      }
      return LoadR;
    }
```
Because there must be a reverse operation after the load if it is a reverse load.
In the future, the assertion should be removed after vectorizer supported permutation elimination in SimplifyRecipe.
https://github.com/llvm/llvm-project/pull/146525
    
    
More information about the llvm-commits
mailing list