Skip to content

[TableGen] Avoid emitting a switch that only contains a default.#177391

Merged
topperc merged 1 commit intollvm:mainfrom
topperc:pr/default-only-switch
Jan 22, 2026
Merged

[TableGen] Avoid emitting a switch that only contains a default.#177391
topperc merged 1 commit intollvm:mainfrom
topperc:pr/default-only-switch

Conversation

@topperc
Copy link
Collaborator

@topperc topperc commented Jan 22, 2026

Addresses post commit feedback from #174471

@llvmbot
Copy link
Member

llvmbot commented Jan 22, 2026

@llvm/pr-subscribers-tablegen

@llvm/pr-subscribers-llvm-selectiondag

Author: Craig Topper (topperc)

Changes

Addresses post commit feedback from #174471


Full diff: https://github.com/llvm/llvm-project/pull/177391.diff

1 Files Affected:

  • (modified) llvm/utils/TableGen/DAGISelMatcherEmitter.cpp (+16-12)
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index eaecccf215342..0ab19d686714f 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -1364,19 +1364,23 @@ void MatcherTableEmitter::EmitValueTypeFunction(raw_ostream &OS) {
 
   for (const auto &[VTs, Idx] : ValueTypeMap) {
     OS << "  case " << (Idx - 1) << ":\n";
-    OS << "    switch (HwMode) {\n";
-    if (!VTs.hasDefault())
-      OS << "    default:\n      return MVT();\n";
-    for (const auto [Mode, VT] : VTs) {
-      if (Mode == DefaultMode)
-        OS << "    default:\n";
-      else
-        OS << "    case " << Mode << ":\n";
-      OS << "      return " << getEnumName(VT) << ";\n";
-    }
+    if (VTs.isSimple()) {
+      OS << "    return " << getEnumName(VTs.getSimple()) << ";\n";
+    } else {
+      OS << "    switch (HwMode) {\n";
+      if (!VTs.hasDefault())
+        OS << "    default:\n      return MVT();\n";
+      for (const auto [Mode, VT] : VTs) {
+        if (Mode == DefaultMode)
+          OS << "    default:\n";
+        else
+          OS << "    case " << Mode << ":\n";
+        OS << "      return " << getEnumName(VT) << ";\n";
+      }
 
-    OS << "    }\n";
-    OS << "    break;\n";
+      OS << "    }\n";
+      OS << "    break;\n";
+    }
   }
 
   OS << "  }\n";

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad warning to have enabled on generated code but ok

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cheers!

@topperc topperc merged commit f18b4ec into llvm:main Jan 22, 2026
12 of 13 checks passed
@topperc topperc deleted the pr/default-only-switch branch January 22, 2026 17:30
Harrish92 pushed a commit to Harrish92/llvm-project that referenced this pull request Jan 23, 2026
Harrish92 pushed a commit to Harrish92/llvm-project that referenced this pull request Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:SelectionDAG SelectionDAGISel as well tablegen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants