[SystemZ] Fix invalid assumption in getCPUNameFromS390Model
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 20 Jul 2021 11:36:33 +0000 (13:36 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 20 Jul 2021 11:39:22 +0000 (13:39 +0200)
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.

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

index 1ecfef95fdffb019811aa0a13e9e8b5d04ee7c9c..3336587aa85b7ee5209b0685e4f0aa3bde52baa8 100644 (file)
@@ -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
 
index a7d39bee8b30b5097ad21734b5d9c69be947a022..6e7f95e228a3bb468e8eb179599916ebd18f3f70 100644 (file)
@@ -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");