[llvm] [SelectionDAG] Provide context for vector count / type mismatch (PR #175433)

Trevor Gross via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 11 04:13:53 PST 2026


https://github.com/tgross35 created https://github.com/llvm/llvm-project/pull/175433

This now gives better details about what the mismatch is, e.g.:

>From 6de086255380048e46e5823605deb8704ffd83b6 Mon Sep 17 00:00:00 2001
From: Trevor Gross <tg at trevorgross.com>
Date: Sun, 11 Jan 2026 01:26:43 -0500
Subject: [PATCH] [SelectionDAG] Provide context for vector count / type
 mismatch

This now gives better details about what the mismatch is, e.g.:
---
 llvm/include/llvm/CodeGenTypes/MachineValueType.h |  3 +++
 .../CodeGen/SelectionDAG/SelectionDAGBuilder.cpp  | 15 ++++++++++++---
 llvm/lib/CodeGen/ValueTypes.cpp                   | 12 ++++++++----
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/CodeGenTypes/MachineValueType.h b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
index 08a9c85a213e0..64687d515d21a 100644
--- a/llvm/include/llvm/CodeGenTypes/MachineValueType.h
+++ b/llvm/include/llvm/CodeGenTypes/MachineValueType.h
@@ -64,6 +64,9 @@ namespace llvm {
     bool operator>=(const MVT& S) const { return SimpleTy >= S.SimpleTy; }
     bool operator<=(const MVT& S) const { return SimpleTy <= S.SimpleTy; }
 
+    /// Return the value type as a string, e.g. `i32`.
+    std::string getString() const;
+
     /// Support for debugging, callable in GDB: VT.dump()
     LLVM_ABI void dump() const;
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index bff4799963fc2..f4ae2f3cd6c44 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -769,9 +769,18 @@ static void getCopyToPartsVector(SelectionDAG &DAG, const SDLoc &DL,
                                    NumIntermediates, RegisterVT);
   }
 
-  assert(NumRegs == NumParts && "Part count doesn't match vector breakdown!");
-  NumParts = NumRegs; // Silence a compiler warning.
-  assert(RegisterVT == PartVT && "Part type doesn't match vector breakdown!");
+
+  if (NumRegs != NumParts || RegisterVT != PartVT)
+    report_fatal_error(Twine("Part count doesn't match vector breakdown! ")
+                           .concat(Twine(NumRegs))
+                           .concat("registers, ")
+                           .concat(Twine(NumParts))
+                           .concat(" parts, ")
+                           .concat(Twine(RegisterVT.getString()))
+                           .concat(" RegisterVT, ")
+                           .concat(Twine(PartVT.getString()))
+                           .concat(" PartVT")
+                         );
 
   assert(IntermediateVT.isScalableVector() == ValueVT.isScalableVector() &&
          "Mixing scalable and fixed vectors when copying in parts");
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index 0743c92c5b95b..15dadfcf865e4 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -333,6 +333,13 @@ const fltSemantics &EVT::getFltSemantics() const {
   return getScalarType().getSimpleVT().getFltSemantics();
 }
 
+std::string MVT::getString() const {
+  if (SimpleTy == INVALID_SIMPLE_VALUE_TYPE)
+    return "invalid";
+
+  return EVT(*this).getEVTString();
+}
+
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 void MVT::dump() const {
   print(dbgs());
@@ -341,8 +348,5 @@ void MVT::dump() const {
 #endif
 
 void MVT::print(raw_ostream &OS) const {
-  if (SimpleTy == INVALID_SIMPLE_VALUE_TYPE)
-    OS << "invalid";
-  else
-    OS << EVT(*this).getEVTString();
+  OS << getString();
 }



More information about the llvm-commits mailing list