Skip to content

[llvm-exegesis] Align loop MBB in loop repetitor #77264

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

Conversation

boomanaiden154
Copy link
Contributor

@boomanaiden154 boomanaiden154 commented Jan 8, 2024

This patch sets the alignment of the loob MBB in the loop repetitor to 16 to avoid instruction fetch/predecoding bottlenecks that can come up with unaligned code. The value of 16 was chosen based on numbers for recent Intel microarchitectures and reccomendations from Agner Fog.

Fixes #77259.

This patch sets the alignment of the loob MBB in the loop repetitor to
16 to avoid instruction fetch/predecoding bottlenecks that can come up
with unaligned code. The value of 16 was chosen based on numbers for
recent Intel microarchitectures and reccomendations from Agner Fog.
@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2024

@llvm/pr-subscribers-tools-llvm-exegesis

Author: Aiden Grossman (boomanaiden154)

Changes

This patch sets the alignment of the loob MBB in the loop repetitor to 16 to avoid instruction fetch/predecoding bottlenecks that can come up with unaligned code. The value of 16 was chosen based on numbers for recent Intel microarchitectures and reccomendations from Agner Fog.


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

1 Files Affected:

  • (modified) llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp (+4)
diff --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
index cc5a045a8be5dd..2e23351de8e0dc 100644
--- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
@@ -74,6 +74,10 @@ class LoopSnippetRepetitor : public SnippetRepetitor {
       auto Loop = Filler.addBasicBlock();
       auto Exit = Filler.addBasicBlock();
 
+      // Align the loop machine basic block to a sixteen byte boundary
+      // so that instruction fetch on modern x86 platforms works optimally.
+      Loop.MBB->setAlignment(Align(16));
+
       const unsigned LoopUnrollFactor =
           LoopBodySize <= Instructions.size()
               ? 1

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

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

LGTM - cheers

@phoebewang
Copy link
Contributor

Not quite understand the background, but want to share to see if the recent feature #71026 helps with this.

@boomanaiden154
Copy link
Contributor Author

Not quite understand the background, but want to share to see if the recent feature #71026 helps with this.

Thank you for pointing this out. We don't lower anything from LLVM IR and generate machine code directly for benchmarks in llvm-exegesis, so this isn't applicable with the way we're doing things currently.

@boomanaiden154 boomanaiden154 merged commit 7173ae9 into llvm:main Jan 8, 2024
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
This patch sets the alignment of the loob MBB in the loop repetitor to
16 to avoid instruction fetch/predecoding bottlenecks that can come up
with unaligned code. The value of 16 was chosen based on numbers for
recent Intel microarchitectures and reccomendations from Agner Fog.

Fixes llvm#77259.
@boomanaiden154 boomanaiden154 deleted the exegesis-loop-repetitor-code-alignment branch January 30, 2025 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[llvm-exegesis] Measurement values sometimes doubled
5 participants