[llvm] 626e2d2 - [AArch64] Avoid raw_svector_ostream for SubtargetMap keys (#196003)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 23:43:39 PDT 2026


Author: Cullen Rhodes
Date: 2026-05-07T07:43:34+01:00
New Revision: 626e2d239765b9bed28ab2af4649adafcb84a5dc

URL: https://github.com/llvm/llvm-project/commit/626e2d239765b9bed28ab2af4649adafcb84a5dc
DIFF: https://github.com/llvm/llvm-project/commit/626e2d239765b9bed28ab2af4649adafcb84a5dc.diff

LOG: [AArch64] Avoid raw_svector_ostream for SubtargetMap keys (#196003)

AArch64TargetMachine::getSubtargetImpl builds a StringMap key on every
subtarget lookup. This showed up through repeated TTI queries while
profiling sqlite on aarch64-O0-g.

Building the key directly with SmallString appends and utostr instead of
raw_svector_ostream improves compile-time.

We used to do this until 07e7168048b1.

CTMark geomean:
- stage1-aarch64-O3: -0.16%
- stage1-aarch64-O0-g: -0.18%

https://llvm-compile-time-tracker.com/compare.php?from=c9d713aa48a714d20b8502d06b9feb24829e6f22&to=e7ff83884193ee70cf3a69778b891fb729e0bcba&stat=instructions%3Au

Assisted-by: codex

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index e07245a600c4f..226fc380a9244 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -19,6 +19,7 @@
 #include "AArch64TargetTransformInfo.h"
 #include "MCTargetDesc/AArch64MCTargetDesc.h"
 #include "TargetInfo/AArch64TargetInfo.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/CodeGen/CSEConfigBase.h"
@@ -461,11 +462,21 @@ AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
   }
 
   SmallString<512> Key;
-  raw_svector_ostream(Key) << "SVEMin" << MinSVEVectorSize << "SVEMax"
-                           << MaxSVEVectorSize << "IsStreaming=" << IsStreaming
-                           << "IsStreamingCompatible=" << IsStreamingCompatible
-                           << CPU << TuneCPU << FS
-                           << "HasMinSize=" << HasMinSize;
+  // This lookup is hot during repeated TTI queries, so build the key directly
+  // instead of formatting through raw_svector_ostream.
+  Key += "SVEMin";
+  Key += utostr(MinSVEVectorSize);
+  Key += "SVEMax";
+  Key += utostr(MaxSVEVectorSize);
+  Key += "IsStreaming=";
+  Key += utostr(IsStreaming);
+  Key += "IsStreamingCompatible=";
+  Key += utostr(IsStreamingCompatible);
+  Key += CPU;
+  Key += TuneCPU;
+  Key += FS;
+  Key += "HasMinSize=";
+  Key += utostr(HasMinSize);
 
   auto &I = SubtargetMap[Key];
   if (!I) {


        


More information about the llvm-commits mailing list