[llvm] Revert -mcpu fix (PR #174093)

Amina Chabane via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 31 06:39:19 PST 2025


https://github.com/Amichaxx updated https://github.com/llvm/llvm-project/pull/174093

>From b9f02c76b1c836e9706b3a8a97c0cf8fd7457b98 Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Wed, 31 Dec 2025 13:11:57 +0000
Subject: [PATCH 1/2] Revert "Ignore host -mcpu when target lacks that CPU"

This reverts commit 8920797f8f5845df0ffd717816c4806cf05c4128.
---
 .../llvm-mca/{AArch64 => }/mcpu-help.test     |  0
 llvm/tools/llvm-mca/llvm-mca.cpp              | 44 ++++---------------
 2 files changed, 8 insertions(+), 36 deletions(-)
 rename llvm/test/tools/llvm-mca/{AArch64 => }/mcpu-help.test (100%)

diff --git a/llvm/test/tools/llvm-mca/AArch64/mcpu-help.test b/llvm/test/tools/llvm-mca/mcpu-help.test
similarity index 100%
rename from llvm/test/tools/llvm-mca/AArch64/mcpu-help.test
rename to llvm/test/tools/llvm-mca/mcpu-help.test
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index 45fa4973d4399..c4aa081a095f8 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -392,6 +392,9 @@ int main(int argc, char **argv) {
   if (!TheTarget)
     return 1;
 
+  if (MCPU == "native")
+    MCPU = std::string(llvm::sys::getHostCPUName());
+
   // Package up features to be passed to target/subtarget
   std::string FeaturesStr;
   if (MATTRS.size()) {
@@ -401,44 +404,13 @@ int main(int argc, char **argv) {
     FeaturesStr = Features.getString();
   }
 
-  auto CreateSubtargetInfo = [&](StringRef CPU) {
-    return std::unique_ptr<MCSubtargetInfo>(
-        TheTarget->createMCSubtargetInfo(TheTriple, CPU, FeaturesStr));
-  };
-
-  std::unique_ptr<MCSubtargetInfo> STI;
-  if (MCPU == "native") {
-    std::string HostCPU = std::string(llvm::sys::getHostCPUName());
-    STI = CreateSubtargetInfo("");
-    if (!STI) {
-      WithColor::error() << "unable to create subtarget info\n";
-      return 1;
-    }
-    if (!HostCPU.empty() && STI->isCPUStringValid(HostCPU)) {
-      // Only utilise the detected host CPU when it exists in the processor
-      // table for the requested triple.
-      STI = CreateSubtargetInfo(HostCPU);
-      if (!STI) {
-        WithColor::error() << "unable to create subtarget info\n";
-        return 1;
-      }
-      MCPU = HostCPU;
-    } else {
-      MCPU.clear();
-    }
-  } else {
-    STI = CreateSubtargetInfo(MCPU);
-    if (!STI) {
-      WithColor::error() << "unable to create subtarget info\n";
-      return 1;
-    }
+  std::unique_ptr<MCSubtargetInfo> STI(
+      TheTarget->createMCSubtargetInfo(TheTriple, MCPU, FeaturesStr));
+  if (!STI) {
+    WithColor::error() << "unable to create subtarget info\n";
+    return 1;
   }
 
-  if (MCPU.empty())
-    // MCPU being empty here means the target default was selected above,
-    // which avoids forwarding incompatible host CPUs when cross-compiling.
-    MCPU = std::string(STI->getCPU());
-
   if (MCPU == "help")
     return 0;
 

>From 4be452691e3ef9e6913f6d08df7ab819a12e506c Mon Sep 17 00:00:00 2001
From: Amichaxx <amina.chabane at arm.com>
Date: Wed, 31 Dec 2025 13:13:13 +0000
Subject: [PATCH 2/2] Revert "[MCA] Fix -mcpu=help flag"

This reverts commit 8fa1001a2bc103faec8d45b9544463c8f31e0ed1.
---
 llvm/test/tools/llvm-mca/mcpu-help.test | 11 -----------
 llvm/tools/llvm-mca/llvm-mca.cpp        | 17 +++++++----------
 2 files changed, 7 insertions(+), 21 deletions(-)
 delete mode 100644 llvm/test/tools/llvm-mca/mcpu-help.test

diff --git a/llvm/test/tools/llvm-mca/mcpu-help.test b/llvm/test/tools/llvm-mca/mcpu-help.test
deleted file mode 100644
index 55168b4080c0c..0000000000000
--- a/llvm/test/tools/llvm-mca/mcpu-help.test
+++ /dev/null
@@ -1,11 +0,0 @@
-# REQUIRES: aarch64-registered-target
-
-# RUN: llvm-mca -mtriple=aarch64-unknown-linux-gnu -mcpu=help %t.no-input 2>&1 | FileCheck %s
-
-// Ensures -mcpu=help still prints the CPU/features lists even when the input file after the flag is nonexistent.
-
-# CHECK: Available CPUs for this target:
-# CHECK: a64fx           - Select the a64fx processor.
-# CHECK: ampere1         - Select the ampere1 processor.
-# CHECK: Available features for this target:
-# CHECK-NOT: error:
diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp
index c4aa081a095f8..a64539c09b81e 100644
--- a/llvm/tools/llvm-mca/llvm-mca.cpp
+++ b/llvm/tools/llvm-mca/llvm-mca.cpp
@@ -392,6 +392,13 @@ int main(int argc, char **argv) {
   if (!TheTarget)
     return 1;
 
+  ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
+      MemoryBuffer::getFileOrSTDIN(InputFilename);
+  if (std::error_code EC = BufferPtr.getError()) {
+    WithColor::error() << InputFilename << ": " << EC.message() << '\n';
+    return 1;
+  }
+
   if (MCPU == "native")
     MCPU = std::string(llvm::sys::getHostCPUName());
 
@@ -411,19 +418,9 @@ int main(int argc, char **argv) {
     return 1;
   }
 
-  if (MCPU == "help")
-    return 0;
-
   if (!STI->isCPUStringValid(MCPU))
     return 1;
 
-  ErrorOr<std::unique_ptr<MemoryBuffer>> BufferPtr =
-      MemoryBuffer::getFileOrSTDIN(InputFilename);
-  if (std::error_code EC = BufferPtr.getError()) {
-    WithColor::error() << InputFilename << ": " << EC.message() << '\n';
-    return 1;
-  }
-
   if (!STI->getSchedModel().hasInstrSchedModel()) {
     WithColor::error()
         << "unable to find instruction-level scheduling information for"



More information about the llvm-commits mailing list