[llvm] [MIRParser] Reject a one-element fixed-length vector type (PR #213290)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 09:21:58 PDT 2026


https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/213290

>From 07ffae78205833accb71135ef8665d423f60fdf7 Mon Sep 17 00:00:00 2001
From: Taimuraz Kaitmazov <atassikay38 at gmail.com>
Date: Fri, 31 Jul 2026 18:07:41 +0300
Subject: [PATCH 1/3] [MIRParser] Reject a one-element fixed-length vector type

MIParser accepts <1 x sN>, then LLT::vector asserts on it:

  llc: LowLevelType.h:72: static LLT llvm::LLT::vector(ElementCount, LLT):
  Assertion `!EC.isScalar() && "invalid number of vector elements"' failed.

LLT has no one-element fixed-length vector. getLLTForType, getLLTForMVT and
LLT::changeElementCount all map such a type to the element type itself via
LLT::scalarOrVector, so nothing can produce one, and no in-tree .mir test
uses the syntax. verifyVectorElementCount already rejects 0 and anything
above 2^16, so 1 was the one remaining hole; it now reports the same
diagnostic instead of aborting the parser.

Scalable vectors are unaffected: <vscale x 1 x sN> is a valid type, kept
legal by the HasVScale check and covered by
CodeGen/MIR/Generic/scalable-vector-type.mir.
---
 llvm/lib/CodeGen/MIRParser/MIParser.cpp                |  9 ++++++---
 .../MIR/AArch64/parse-low-level-type-invalid11.mir     | 10 ++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir

diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 4b951785e9c41..71dbc5171ed20 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -1965,8 +1965,11 @@ static bool verifyScalarSize(uint64_t Size) {
   return Size != 0 && isUInt<16>(Size);
 }
 
-static bool verifyVectorElementCount(uint64_t NumElts) {
-  return NumElts != 0 && isUInt<16>(NumElts);
+static bool verifyVectorElementCount(uint64_t NumElts, bool HasVScale) {
+  // A fixed-length vector needs at least two elements: LLT::vector rejects a
+  // one-element ElementCount, and producers map such a type to the element
+  // type itself through LLT::scalarOrVector.
+  return NumElts != 0 && (HasVScale || NumElts != 1) && isUInt<16>(NumElts);
 }
 
 static bool verifyAddrSpace(uint64_t AddrSpace) {
@@ -2053,7 +2056,7 @@ bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
   if (Token.isNot(MIToken::IntegerLiteral))
     return GetError();
   uint64_t NumElements = Token.integerValue().getZExtValue();
-  if (!verifyVectorElementCount(NumElements))
+  if (!verifyVectorElementCount(NumElements, HasVScale))
     return error("invalid number of vector elements");
 
   lex();
diff --git a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir
new file mode 100644
index 0000000000000..7bce51dc5dafb
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir
@@ -0,0 +1,10 @@
+# RUN: not llc -mtriple=aarch64-- -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# When a fixed-length low-level type vector has 1 element
+---
+name: test_vector_1_element
+body: |
+  bb.0:
+    liveins: $x0
+    ; CHECK: [[@LINE+1]]:11: invalid number of vector elements
+    %0:_(<1 x s64>) = G_IMPLICIT_DEF
+...

>From d0b9f679efe7746f26e3fb80514b91f1ec947c2b Mon Sep 17 00:00:00 2001
From: Taimuraz Kaitmazov <atassikay38 at gmail.com>
Date: Fri, 31 Jul 2026 18:54:32 +0300
Subject: [PATCH 2/3] Use -run-pass=none -filetype=null in the new test

---
 .../test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir
index 7bce51dc5dafb..1a1e71ad28729 100644
--- a/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir
+++ b/llvm/test/CodeGen/MIR/AArch64/parse-low-level-type-invalid11.mir
@@ -1,4 +1,4 @@
-# RUN: not llc -mtriple=aarch64-- -run-pass none -o /dev/null %s 2>&1 | FileCheck %s
+# RUN: not llc -mtriple=aarch64-- -run-pass=none -filetype=null %s 2>&1 | FileCheck %s
 # When a fixed-length low-level type vector has 1 element
 ---
 name: test_vector_1_element

>From f08baca5ffc3ae57fe07f4aef96b267dd1bf3512 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <arsenm2 at gmail.com>
Date: Sun, 13 Sep 2026 18:21:49 +0200
Subject: [PATCH 3/3] Simplify comment

---
 llvm/lib/CodeGen/MIRParser/MIParser.cpp | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
index 71dbc5171ed20..7b45d028efdd7 100644
--- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp
@@ -1966,9 +1966,7 @@ static bool verifyScalarSize(uint64_t Size) {
 }
 
 static bool verifyVectorElementCount(uint64_t NumElts, bool HasVScale) {
-  // A fixed-length vector needs at least two elements: LLT::vector rejects a
-  // one-element ElementCount, and producers map such a type to the element
-  // type itself through LLT::scalarOrVector.
+  // A fixed-length vector needs at least two elements.
   return NumElts != 0 && (HasVScale || NumElts != 1) && isUInt<16>(NumElts);
 }
 



More information about the llvm-commits mailing list