[Mlir-commits] [mlir] [mlir][quant] Fix printer to preserve non-signless storage type (PR #187300)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Mar 18 08:23:45 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: German Gambon (ggambon)
<details>
<summary>Changes</summary>
## Summary
- Fix `IntegerType::getStorageTypeName()` to print the actual type (e.g. `ui8`, `si8`) when the storage type is non-signless, instead of always using the `isSigned` flag to choose between `i`/`u` prefix
- Without the fix, bytecode serialization roundtrip breaks for types that don't have custom bytecode serializers and contain quant types, since the fallback text printer coerces non-signless storage types to signless (e.g. `ui8` → `u8`, `si8` → `i8`)
- Add roundtrip tests for `ui8` and `si8` storage types
## Test plan
- [x] All 13 quant dialect tests pass
- [x] Bytecode roundtrip test passes
- [x] New `ui8`/`si8` test cases pass with fix, fail without
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---
Full diff: https://github.com/llvm/llvm-project/pull/187300.diff
2 Files Affected:
- (modified) mlir/include/mlir/IR/BuiltinTypes.td (+7-1)
- (modified) mlir/test/Dialect/Quant/parse-uniform.mlir (+18)
``````````diff
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/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}>
``````````
</details>
https://github.com/llvm/llvm-project/pull/187300
More information about the Mlir-commits
mailing list