[llvm] 57a6f65 - [LV] Simplify condition for induction recipe insertion (NFCI).

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 07:58:15 PDT 2023


Author: Florian Hahn
Date: 2023-08-21T15:58:07+01:00
New Revision: 57a6f6579c97cd68815092d6238a54e193a06c01

URL: https://github.com/llvm/llvm-project/commit/57a6f6579c97cd68815092d6238a54e193a06c01
DIFF: https://github.com/llvm/llvm-project/commit/57a6f6579c97cd68815092d6238a54e193a06c01.diff

LOG: [LV] Simplify condition for induction recipe insertion (NFCI).

Split off independent suggestion from D157037. This simplifies the
condition to decide if a recipe needs to be inserted to the header phi
section or simply appended.

The assertion has been updated to allow cases where the first non-phi
recipe is the end of the block, in which case inserting before this
point is equivalent to appending.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index c2b0f15268d7a1..ddfc490e6942b4 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8805,11 +8805,14 @@ LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(VFRange &Range) {
       }
 
       RecipeBuilder.setRecipe(Instr, Recipe);
-      if (isa<VPWidenIntOrFpInductionRecipe>(Recipe) &&
-          HeaderVPBB->getFirstNonPhi() != VPBB->end()) {
-        // Move VPWidenIntOrFpInductionRecipes for optimized truncates to the
+      if (isa<VPWidenIntOrFpInductionRecipe>(Recipe)) {
+        // VPWidenIntOrFpInductionRecipes must be kept in the phi section of
+        // HeaderVPBB. VPWidenIntOrFpInductionRecipes for optimized truncates
+        // may be generated after non-phi recipes and need to be moved to the
         // phi section of HeaderVPBB.
-        assert(isa<TruncInst>(Instr));
+        assert((HeaderVPBB->getFirstNonPhi() == VPBB->end() ||
+                isa<TruncInst>(Instr)) &&
+               "unexpected recipe needs moving");
         Recipe->insertBefore(*HeaderVPBB, HeaderVPBB->getFirstNonPhi());
       } else
         VPBB->appendRecipe(Recipe);


        


More information about the llvm-commits mailing list