[llvm] [VPlan] Create AVL as a phi from TC -> 0 with EVL tail folding (PR #151481)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 31 03:06:50 PDT 2025
================
@@ -2350,9 +2350,11 @@ bool VPlanTransforms::tryAddExplicitVectorLength(
auto *EVLPhi = new VPEVLBasedIVPHIRecipe(StartV, DebugLoc());
EVLPhi->insertAfter(CanonicalIVPHI);
VPBuilder Builder(Header, Header->getFirstNonPhi());
- // Compute original TC - IV as the AVL (application vector length).
- VPValue *AVL = Builder.createNaryOp(
- Instruction::Sub, {Plan.getTripCount(), EVLPhi}, DebugLoc(), "avl");
+ // Create the AVL, starting from TC -> 0 in steps of EVL.
+ VPPhi *AVLPhi =
+ Builder.createScalarPhi({Plan.getTripCount()}, DebugLoc(), "avl");
+ VPValue *AVL = AVLPhi;
----------------
lukel97 wrote:
I did this at first and got some confusing test failures, it turns out we need to keep a reference to the phi because the `AVL = Builder.createSelect(Cmp, AVL, AVLSafe, DebugLoc(), "safe_avl");` bit below might reassign the AVL, and we would end up adding the backedge to the select
https://github.com/llvm/llvm-project/pull/151481
More information about the llvm-commits
mailing list