[llvm] [llvm-exegesis] Align loop MBB in loop repetitor (PR #77264)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 8 00:07:25 PST 2024
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/77264
>From 68995cfffc153c824d68ada531ddf8b7cc94daab Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Sun, 7 Jan 2024 17:42:39 -0800
Subject: [PATCH 1/2] [llvm-exegesis] Align loop MBB in loop repetitor
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.
---
llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp | 4 ++++
1 file changed, 4 insertions(+)
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
>From b8fbfafb6f5f220dfb2c80446d2b3649da6196f5 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <agrossman154 at yahoo.com>
Date: Mon, 8 Jan 2024 00:07:15 -0800
Subject: [PATCH 2/2] Switch to target specific loop alignment hook
---
llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
index 2e23351de8e0dc..1872f550c3f310 100644
--- a/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
+++ b/llvm/tools/llvm-exegesis/lib/SnippetRepetitor.cpp
@@ -10,6 +10,7 @@
#include "Target.h"
#include "llvm/ADT/Sequence.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
namespace llvm {
@@ -74,9 +75,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));
+ // Align the loop machine basic block to a target-specific boundary
+ // to promote optimal instruction fetch/predecoding conditions.
+ Loop.MBB->setAlignment(
+ Filler.MF.getSubtarget().getTargetLowering()->getPrefLoopAlignment());
const unsigned LoopUnrollFactor =
LoopBodySize <= Instructions.size()
More information about the llvm-commits
mailing list