[llvm] [MGLO] Add Threshold to Prevent Pathological Compile Time Cases (PR #119807)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 12 19:29:21 PST 2024


https://github.com/boomanaiden154 created https://github.com/llvm/llvm-project/pull/119807

This patch adds a threshold flag, -mlregalloc-max-cascade, to prevent live ranges from being evicted more than is necessary.

After deploying a new regalloc model, we ran into some pathological cases where the model decided it wanted to ping-pong evictions, taking up a large amount of compile time. This threshold is mostly a stop gap while we continue to investigate other solutions and work on minimizing/constructing test cases.

>From 2894d91b4c9358d98e32f41ef2cb8384867706de Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Fri, 13 Dec 2024 03:20:36 +0000
Subject: [PATCH] [MGLO] Add Threshold to Prevent Pathological Compile Time
 Cases

This patch adds a threshold flag, -mlregalloc-max-cascade, to prevent
live ranges from being evicted more than is necessary.

After deploying a new regalloc model, we ran into some pathological
cases where the model decided it wanted to ping-pong evictions, taking
up a large amount of compile time. This threshold is mostly a stop gap
while we continue to investigate other solutions and work on
minimizing/constructing test cases.
---
 llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 03f015f8c9e32d..e202dd45cfed50 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -63,6 +63,12 @@ static cl::opt<std::string> InteractiveChannelBaseName(
         "outgoing name should be "
         "<regalloc-evict-interactive-channel-base>.out"));
 
+static cl::opt<unsigned>
+    MaxCascade("mlregalloc-max-cascade", cl::Hidden,
+               cl::desc("The maximum number of times a live range can be "
+                        "evicted before preventing it from being evicted"),
+               cl::init(20));
+
 // Options that only make sense in development mode
 #ifdef LLVM_HAVE_TFLITE
 #include "RegAllocScore.h"
@@ -643,8 +649,16 @@ bool MLEvictAdvisor::loadInterferenceFeatures(
            RegClassInfo.getNumAllocatableRegs(MRI->getRegClass(VirtReg.reg())) <
                RegClassInfo.getNumAllocatableRegs(
                    MRI->getRegClass(Intf->reg())));
-      // Only evict older cascades or live ranges without a cascade.
+
       unsigned IntfCascade = RA.getExtraInfo().getCascade(Intf->reg());
+      // There is a potential that the model could be adversarial and
+      // continually evict live ranges over and over again, leading to a
+      // large amount of compile time being spent in regalloc. If we hit the
+      // threshold, prevent the range from being evicted.
+      if (IntfCascade >= MaxCascade)
+        return false;
+
+      // Only evict older cascades or live ranges without a cascade.
       if (Cascade <= IntfCascade) {
         if (!Urgent)
           return false;



More information about the llvm-commits mailing list