[llvm] [AArch64] Add flag to control unrolling for small multi-exit loops (PR #131998)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 20 06:36:53 PDT 2025


================
@@ -4237,6 +4242,70 @@ getFalkorUnrollingPreferences(Loop *L, ScalarEvolution &SE,
   }
 }
 
+static bool shouldUnrollLoopWithInstruction(Instruction &I,
+                                            AArch64TTIImpl &TTI) {
+  // Don't unroll vectorised loop.
+  if (I.getType()->isVectorTy())
+    return false;
+
+  if (isa<CallInst>(I) || isa<InvokeInst>(I)) {
+    if (const Function *F = cast<CallBase>(I).getCalledFunction())
+      if (!TTI.isLoweredToCall(F))
+        return true;
+    return false;
+  }
+
+  return true;
+}
+
+static bool shouldUnrollSmallMultiExitLoop(Loop *L, ScalarEvolution &SE,
----------------
david-arm wrote:

Hi, I'm not sure exactly what you meant by 'unify' and how far I should attempt to commonise code. I've tried my best - see what you think! The main difference is that now getAppleRuntimeUnrollPreferences bails out on multi-exit loops and defers to common code. The common code bails out for slightly more cases, for example if an intrinsic gets lowered to a call, if the loop already contains a vector type, or if a cost cannot be calculated. I assume that these are sensible things to do for all targets anyway. One side-effect of these changes is that it's now possible to override the default unroll factor of 4 - I've added a test to Transforms/LoopUnroll/AArch64/apple-unrolling-multi-exit.ll for forcing unroll=2.

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


More information about the llvm-commits mailing list