[llvm] [CodeGen] Call getMCPU once instead of commonly twice (PR #186581)

Tomer Shafir via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 14 03:14:16 PDT 2026


https://github.com/tomershafir created https://github.com/llvm/llvm-project/pull/186581

None

>From 63585ac815315ec24f0d06db498a971ae3af6d95 Mon Sep 17 00:00:00 2001
From: tomershafir <tomer.shafir8 at gmail.com>
Date: Sat, 14 Mar 2026 12:09:39 +0200
Subject: [PATCH] [CodeGen] Call getMCPU once instead of commonly twice (NFC)

---
 llvm/lib/CodeGen/CommandFlags.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 24f74dbd28b61..0047f50e48373 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -644,13 +644,15 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
 }
 
 std::string codegen::getCPUStr() {
+  std::string MCPU = getMCPU();
+
   // If user asked for the 'native' CPU, autodetect here. If autodection fails,
   // this will set the CPU to an empty string which tells the target to
   // pick a basic default.
-  if (getMCPU() == "native")
+  if (MCPU == "native")
     return std::string(sys::getHostCPUName());
 
-  return getMCPU();
+  return MCPU;
 }
 
 std::string codegen::getFeaturesStr() {



More information about the llvm-commits mailing list