[llvm] [AArch64][TTI] Surface per-CPU branch misprediction penalty to SimplifyCFG (PR #201484)

Kunal Pathak via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 18:09:58 PDT 2026


https://github.com/kunalspathak updated https://github.com/llvm/llvm-project/pull/201484

>From e7220f393132947d9f64e3f1f65db3602ad71ae5 Mon Sep 17 00:00:00 2001
From: Kunal Pathak <kupathak at fb.com>
Date: Wed, 3 Jun 2026 16:02:49 -0700
Subject: [PATCH 1/2] Introduce misprediction number for AArch64

---
 llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 5 +++++
 llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h   | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 730bec428a38e..7cc6fab8042dd 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -568,6 +568,11 @@ AArch64TTIImpl::getPopcntSupport(unsigned TyWidth) const {
   return TTI::PSK_Software;
 }
 
+InstructionCost AArch64TTIImpl::getBranchMispredictPenalty() const {
+  // MispredictPenalty is defined per-CPU in AArch64Sched*.td (e.g., AArch64SchedNeoverseV2.td).
+  return ST->getSchedModel().MispredictPenalty;
+}
+
 static bool isUnpackedVectorVT(EVT VecVT) {
   return VecVT.isScalableVector() &&
          VecVT.getSizeInBits().getKnownMinValue() < AArch64::SVEBitsPerBlock;
diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
index 200b4c9fba196..93896e3443765 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
@@ -456,6 +456,8 @@ class AArch64TTIImpl final : public BasicTTIImplBase<AArch64TTIImpl> {
 
   unsigned getGISelRematGlobalCost() const override { return 2; }
 
+  InstructionCost getBranchMispredictPenalty() const override;
+
   unsigned getMinTripCountTailFoldingThreshold() const override {
     return ST->hasSVE() ? 5 : 0;
   }

>From dc982a6273b9823ad957f2d2cd26c4d0357a355f Mon Sep 17 00:00:00 2001
From: Kunal Pathak <kupathak at fb.com>
Date: Wed, 3 Jun 2026 18:09:23 -0700
Subject: [PATCH 2/2] clang format

---
 llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
index 7cc6fab8042dd..a432946b42827 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
@@ -569,7 +569,8 @@ AArch64TTIImpl::getPopcntSupport(unsigned TyWidth) const {
 }
 
 InstructionCost AArch64TTIImpl::getBranchMispredictPenalty() const {
-  // MispredictPenalty is defined per-CPU in AArch64Sched*.td (e.g., AArch64SchedNeoverseV2.td).
+  // MispredictPenalty is defined per-CPU in AArch64Sched*.td (e.g.,
+  // AArch64SchedNeoverseV2.td).
   return ST->getSchedModel().MispredictPenalty;
 }
 



More information about the llvm-commits mailing list