[llvm] [VPlan] Use SCEV optimize VecTC-materialization for scalable (PR #193703)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 23 02:59:55 PDT 2026


================
@@ -5205,6 +5196,30 @@ void VPlanTransforms::materializeVectorTripCount(
   VectorTC.replaceAllUsesWith(Res);
 }
 
+void VPlanTransforms::materializeVectorTripCount(
+    VPlan &Plan, PredicatedScalarEvolution &PSE, VPBasicBlock *VectorPHVPBB,
+    bool TailByMasking, bool RequiresScalarEpilogue, VPValue *Step,
+    uint64_t MaxRuntimeStep) {
+  VPSymbolicValue &VectorTC = Plan.getVectorTripCount();
+  if (VectorTC.getNumUsers() == 0 || VectorTC.getUnderlyingValue())
+    return;
+
+  VPValue *TC = Plan.getTripCount();
+  // For scalable steps, if TC is a constant and is divisible by the maximum
+  // possible runtime step, then TC is divisible by Step for all valid
+  // vscale values and the vector trip count equals TC directly.
+  ScalarEvolution *SE = PSE.getSE();
+  SmallVector<const SCEVPredicate *, 2> Assume;
+  if (!RequiresScalarEpilogue && MaxRuntimeStep &&
+      SE->isKnownMultipleOf(vputils::getSCEVExprForVPValue(TC, PSE),
+                            MaxRuntimeStep, Assume)) {
+    PSE.addPredicate(SCEVUnionPredicate(Assume, *SE));
----------------
fhahn wrote:

SCEV checks already have been created at this point, so this is a no-op and if we need to add assumes they won't get generated.

Adding a SCEV predicate just for that would reject all cases where the trip count is not a multiple, which likely isn't profitable. 

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


More information about the llvm-commits mailing list