[Mlir-commits] [mlir] 1a233a8 - [mlir][quant] Print actual quant storage type when signed (#187300)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Apr 14 10:15:18 PDT 2026


Author: German Gambon
Date: 2026-04-14T17:15:13Z
New Revision: 1a233a8acf836744b1d547c74c27422a57100853

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

LOG: [mlir][quant] Print actual quant storage type when signed (#187300)

Without the fix, bytecode serialization roundtrip breaks for types that
don't have custom bytecode serializers and contain quant types, since
the fallback mechanism prints the type and the quant printer coerces
signed to signless types. E.g. `!custom<!quant.uniform<ui8:f32, 0.1>>`
will print as `u8` when serializing and later be created as a signless
`i8` when deserializing.

Added: 
    

Modified: 
    mlir/include/mlir/IR/BuiltinTypes.td
    mlir/test/Dialect/Quant/Bytecode/types.mlir
    mlir/test/Dialect/Quant/parse-uniform.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/BuiltinTypes.td b/mlir/include/mlir/IR/BuiltinTypes.td
index e7d0a03a85e7d..20c41c5f79729 100644
--- a/mlir/include/mlir/IR/BuiltinTypes.td
+++ b/mlir/include/mlir/IR/BuiltinTypes.td
@@ -680,7 +680,13 @@ def Builtin_Integer : Builtin_Type<"Integer", "integer",
 
     /// Get the storage type as a string.
     std::string getStorageTypeName(bool isSigned) const {
-      return (isSigned ? "i" : "u") + std::to_string(getWidth());
+      if (isSignless()) {
+        return (isSigned ? "i" : "u") + std::to_string(getWidth());
+      } else {
+        std::string s;
+        llvm::raw_string_ostream(s) << *this;
+        return s;
+      }
     }
 
     /// Check if this integer type uses packed representation.

diff  --git a/mlir/test/Dialect/Quant/Bytecode/types.mlir b/mlir/test/Dialect/Quant/Bytecode/types.mlir
index a2eced3ee060d..4b03548a5ad11 100644
--- a/mlir/test/Dialect/Quant/Bytecode/types.mlir
+++ b/mlir/test/Dialect/Quant/Bytecode/types.mlir
@@ -10,6 +10,18 @@ module @parseAnyFullySpecified attributes {
   bytecode.test = !quant.any<i8<-8:7>:f32>
 } {}
 
+// CHECK-LABEL: parseAnyFullySpecifiedUi8
+module @parseAnyFullySpecifiedUi8 attributes {
+  // CHECK: bytecode.test = !quant.any<ui8<0:7>:f32>
+  bytecode.test = !quant.any<ui8<0:7>:f32>
+} {}
+
+// CHECK-LABEL: parseAnyFullySpecifiedSi8
+module @parseAnyFullySpecifiedSi8 attributes {
+  // CHECK: bytecode.test = !quant.any<si8<-8:7>:f32>
+  bytecode.test = !quant.any<si8<-8:7>:f32>
+} {}
+
 // CHECK-LABEL: parseAnyNoExpressedType
 module @parseAnyNoExpressedType attributes {
   // CHECK: bytecode.test = !quant.any<i8<-8:7>>

diff  --git a/mlir/test/Dialect/Quant/parse-uniform.mlir b/mlir/test/Dialect/Quant/parse-uniform.mlir
index 1431403aece41..a8b9e5707b474 100644
--- a/mlir/test/Dialect/Quant/parse-uniform.mlir
+++ b/mlir/test/Dialect/Quant/parse-uniform.mlir
@@ -128,6 +128,24 @@ func.func @parse() -> !qalias {
   return %0 : !qalias
 }
 
+// -----
+// Storage type: ui8 (explicit unsigned)
+// CHECK: !quant.uniform<ui8:f32, 1.000000e+00>
+!qalias = !quant.uniform<ui8:f32, 1.0>
+func.func @parse() -> !qalias {
+  %0 = "foo"() : () -> !qalias
+  return %0 : !qalias
+}
+
+// -----
+// Storage type: si8 (explicit signed)
+// CHECK: !quant.uniform<si8:f32, 1.000000e+00>
+!qalias = !quant.uniform<si8:f32, 1.0>
+func.func @parse() -> !qalias {
+  %0 = "foo"() : () -> !qalias
+  return %0 : !qalias
+}
+
 // -----
 // Per-axis scales and zero points (affine)
 // CHECK: !quant.uniform<u8:f32:1, {2.000000e+02:-120,9.987200e-01:127}>


        


More information about the Mlir-commits mailing list