[llvm] [Arm] Control forced unrolling of small loops (PR #170127)

Vladi Krapp via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 1 04:39:44 PST 2025


https://github.com/VladiKrapp-Arm created https://github.com/llvm/llvm-project/pull/170127

* Add flag to control cost threshold for forced unrolling of loops. Existing value preserved as default.
* Document flag in release notes, along with equivalent Aarch64 flag.

>From add7138b842c5a6f367b201d3b805f6c79e53173 Mon Sep 17 00:00:00 2001
From: Vladi Krapp <vladi.krapp at arm.com>
Date: Mon, 1 Dec 2025 12:01:36 +0000
Subject: [PATCH] [Arm] Control forced unrolling of small loops

* Add flag to control cost threshold for forced unrolling of loops.
  Existing value preserved as default.
* Document flag in release notes, along with equivalent Aarch64 flag.
---
 llvm/docs/ReleaseNotes.md                      | 4 ++++
 llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index c6c527d1ae964..1ec700047ced5 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -111,12 +111,16 @@ Changes to the AArch64 Backend
 * `FEAT_TME` support has been removed, as it has been withdrawn from
    all future versions of the A-profile architecture.
 
+* Allow forced unrolling of small loops. Threshold controlled by flag `aarch64-force-unroll-threshold`
+
 Changes to the AMDGPU Backend
 -----------------------------
 
 Changes to the ARM Backend
 --------------------------
 
+* Allow forced unrolling of small loops. Threshold controlled by flag `arm-force-unroll-threshold` (existing default preserved)
+
 Changes to the AVR Backend
 --------------------------
 
diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
index fdb0ec40cb41f..b5749bf51ce08 100644
--- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
@@ -66,6 +66,10 @@ extern cl::opt<bool> EnableMaskedGatherScatters;
 
 extern cl::opt<unsigned> MVEMaxSupportedInterleaveFactor;
 
+static cl::opt<int> ArmForceUnrollThreshold(
+    "arm-force-unroll-threshold", cl::init(12), cl::Hidden,
+    cl::desc("Threshold for forced unrolling of small loops in Arm architecture"));
+
 /// Convert a vector load intrinsic into a simple llvm load instruction.
 /// This is beneficial when the underlying object being addressed comes
 /// from a constant, since we get constant-folding for free.
@@ -2731,7 +2735,7 @@ void ARMTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
 
   // Force unrolling small loops can be very useful because of the branch
   // taken cost of the backedge.
-  if (Cost < 12)
+  if (Cost < ArmForceUnrollThreshold)
     UP.Force = true;
 }
 



More information about the llvm-commits mailing list