Skip to content

[BOLT][AArch64] Do not relax ADR referencing the same fragment #108673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 14, 2024

Conversation

maksfb
Copy link
Contributor

@maksfb maksfb commented Sep 14, 2024

ADR can reference a secondary entry point in the same function. If that's the case, we can skip relaxing the instruction when it is in the same fragment as its target.

Fixes #108290

ADR can reference a secondary entry point in the same function. If
that's the case, we can skip relaxing the instruction when it is in the
same fragment as its target.

Fixes llvm#108290
@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2024

@llvm/pr-subscribers-bolt

Author: Maksim Panchenko (maksfb)

Changes

ADR can reference a secondary entry point in the same function. If that's the case, we can skip relaxing the instruction when it is in the same fragment as its target.

Fixes #108290


Full diff: https://github.com/llvm/llvm-project/pull/108673.diff

1 Files Affected:

  • (modified) bolt/lib/Passes/ADRRelaxationPass.cpp (+7-2)
diff --git a/bolt/lib/Passes/ADRRelaxationPass.cpp b/bolt/lib/Passes/ADRRelaxationPass.cpp
index 24fddbc764cbe7..256034a841c706 100644
--- a/bolt/lib/Passes/ADRRelaxationPass.cpp
+++ b/bolt/lib/Passes/ADRRelaxationPass.cpp
@@ -59,10 +59,15 @@ void ADRRelaxationPass::runOnFunction(BinaryFunction &BF) {
       // 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) {
+      if (BF.getSize() < OneMB) {
         BinaryFunction *TargetBF = BC.getFunctionForSymbol(Symbol);
-        if (TargetBF && TargetBF == &BF)
+        if (TargetBF == &BF && !BF.isSplit())
           continue;
+        // No relaxation needed if ADR references a basic block in the same
+        // fragment.
+        if (BinaryBasicBlock *TargetBB = BF.getBasicBlockForLabel(Symbol))
+          if (BB.getFragmentNum() == TargetBB->getFragmentNum())
+            continue;
       }
 
       MCPhysReg Reg;

Copy link
Contributor

@aaupov aaupov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

@maksfb maksfb merged commit d32fe95 into llvm:main Sep 14, 2024
7 of 8 checks passed
@yota9
Copy link
Member

yota9 commented Sep 14, 2024

Thanks

@maksfb maksfb deleted the gh-fix-adr branch March 6, 2025 02:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BOLT fails to optimize function
4 participants