[llvm] [VPlan] Compute UncountableExitStyle in VPlan. NFC (PR #206020)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 03:54:03 PDT 2026


================
@@ -4593,13 +4593,38 @@ static bool handleUncountableExitsWithSideEffects(
   return true;
 }
 
+/// Returns true if any non-branch recipe in the loop may have side effects.
+static bool loopHasSideEffects(VPBasicBlock *HeaderVPBB) {
+  for (VPBasicBlock *VPBB : vp_rpo_plain_cfg_loop_body(HeaderVPBB))
+    for (VPRecipeBase &R : *VPBB)
+      if (R.mayHaveSideEffects() && &R != VPBB->getTerminator())
+        return true;
+  return false;
+}
+
 bool VPlanTransforms::handleUncountableEarlyExits(
-    VPlan &Plan, VPBasicBlock *HeaderVPBB, VPBasicBlock *LatchVPBB,
-    VPBasicBlock *MiddleVPBB, Loop *TheLoop, PredicatedScalarEvolution &PSE,
-    DominatorTree &DT, AssumptionCache *AC, UncountableExitStyle Style) {
+    VPlan &Plan, Loop *TheLoop, PredicatedScalarEvolution &PSE,
+    DominatorTree &DT, AssumptionCache *AC) {
 #ifndef NDEBUG
   VPDominatorTree VPDT(Plan);
 #endif
+
+  auto *MiddleVPBB = VPBlockUtils::getPlainCFGMiddleBlock(Plan);
+  auto [HeaderVPBB, LatchVPBB] = VPBlockUtils::getPlainCFGHeaderAndLatch(Plan);
+
+  // TODO: Check target preference for style.
+  UncountableExitStyle Style =
+      loopHasSideEffects(HeaderVPBB)
----------------
huntergr-arm wrote:

Looks ok, though I had planned for the Style to be based (at least partly) on target preference in addition to the presence of side effects. Even in the case where it is a readonly loop, we might want to use a masked style if not all of the loads are guaranteed to be dereferenceable. I guess that can all be done in follow-up work, though, along with fully-masked and check-next-vector-iteration styles as needed.

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


More information about the llvm-commits mailing list