[llvm] [BOLT][AArch64] Fix ADR relaxation (PR #71835)

Vladislav Khmelevsky via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 10:43:17 PST 2023


https://github.com/yota9 updated https://github.com/llvm/llvm-project/pull/71835

>From dec194b066557dc63550e5ef5e0422c1353837d2 Mon Sep 17 00:00:00 2001
From: Vladislav Khmelevsky <och95 at yandex.ru>
Date: Thu, 9 Nov 2023 22:10:38 +0400
Subject: [PATCH] [BOLT][AArch64] Fix ADR relaxation

Currently we have an optimization that if the ADR points to the same
function we might skip it's relaxation. But it doesn't take into account
that BF might be split, in such situation we still need to relax it. And
just in case also relax if the initial BF size is >= 1MB.
Fixes #71822
---
 bolt/lib/Passes/ADRRelaxationPass.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/bolt/lib/Passes/ADRRelaxationPass.cpp b/bolt/lib/Passes/ADRRelaxationPass.cpp
index 7b612cbf6572bd3..ffa58f106ef0c17 100644
--- a/bolt/lib/Passes/ADRRelaxationPass.cpp
+++ b/bolt/lib/Passes/ADRRelaxationPass.cpp
@@ -56,9 +56,14 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
           continue;
       }
 
-      BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
-      if (TargetBF && TargetBF == &BF)
-        continue;
+      // Don't relax adr if it points to the same function and it is not split
+      // and BF initial size is < 1MB.
+      const unsigned OneMB = 0x100000;
+      if (!BF.isSplit() && BF.getSize() < OneMB) {
+        BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
+        if (TargetBF && TargetBF == &BF)
+          continue;
+      }
 
       MCPhysReg Reg;
       BC.MIB->getADRReg(Inst, Reg);



More information about the llvm-commits mailing list