[llvm] e04c05e - [SystemZ] Fix invalid assumption in getCPUNameFromS390Model

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 20 04:40:07 PDT 2021


Author: Ulrich Weigand
Date: 2021-07-20T13:39:22+02:00
New Revision: e04c05e8230e383493774cb3636587d3c0b5f288

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

LOG: [SystemZ] Fix invalid assumption in getCPUNameFromS390Model

Code in getCPUNameFromS390Model currently assumes that the
numerical value of the model number always increases with
future hardware.  While this has happened to be the case
with the last few machines, it is not guaranteed -- that
assumption was violated with (much) older machines, and
it can be violated again with future machines.

Fix by explicitly listing model numbers for all supported
machine models.

Added: 
    

Modified: 
    llvm/lib/Support/Host.cpp
    llvm/unittests/Support/Host.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Host.cpp b/llvm/lib/Support/Host.cpp
index 1ecfef95fdffb..3336587aa85b7 100644
--- a/llvm/lib/Support/Host.cpp
+++ b/llvm/lib/Support/Host.cpp
@@ -299,17 +299,34 @@ StringRef sys::detail::getHostCPUNameForARM(StringRef ProcCpuinfoContent) {
 
 namespace {
 StringRef getCPUNameFromS390Model(unsigned int Id, bool HaveVectorSupport) {
-  if (Id >= 8561 && HaveVectorSupport)
-    return "z15";
-  if (Id >= 3906 && HaveVectorSupport)
-    return "z14";
-  if (Id >= 2964 && HaveVectorSupport)
-    return "z13";
-  if (Id >= 2827)
-    return "zEC12";
-  if (Id >= 2817)
-    return "z196";
-  return "generic";
+  switch (Id) {
+    case 2064:  // z900 not supported by LLVM
+    case 2066:
+    case 2084:  // z990 not supported by LLVM
+    case 2086:
+    case 2094:  // z9-109 not supported by LLVM
+    case 2096:
+      return "generic";
+    case 2097:
+    case 2098:
+      return "z10";
+    case 2817:
+    case 2818:
+      return "z196";
+    case 2827:
+    case 2828:
+      return "zEC12";
+    case 2964:
+    case 2965:
+      return HaveVectorSupport? "z13" : "zEC12";
+    case 3906:
+    case 3907:
+      return HaveVectorSupport? "z14" : "zEC12";
+    case 8561:
+    case 8562:
+    default:
+      return HaveVectorSupport? "z15" : "zEC12";
+  }
 }
 } // end anonymous namespace
 

diff  --git a/llvm/unittests/Support/Host.cpp b/llvm/unittests/Support/Host.cpp
index a7d39bee8b30b..6e7f95e228a3b 100644
--- a/llvm/unittests/Support/Host.cpp
+++ b/llvm/unittests/Support/Host.cpp
@@ -312,7 +312,7 @@ CPU revision    : 0
 
 TEST(getLinuxHostCPUName, s390x) {
   SmallVector<std::string> ModelIDs(
-      {"8561", "3906", "2964", "2827", "2817", "7"});
+      {"8561", "3906", "2964", "2827", "2817", "2097", "2064"});
   SmallVector<std::string> VectorSupport({"", "vx"});
   SmallVector<StringRef> ExpectedCPUs;
 
@@ -336,7 +336,11 @@ TEST(getLinuxHostCPUName, s390x) {
   ExpectedCPUs.push_back("z196");
   ExpectedCPUs.push_back("z196");
 
-  // Model Id: 7
+  // Model Id: 2097
+  ExpectedCPUs.push_back("z10");
+  ExpectedCPUs.push_back("z10");
+
+  // Model Id: 2064
   ExpectedCPUs.push_back("generic");
   ExpectedCPUs.push_back("generic");
 


        


More information about the llvm-commits mailing list