diff --git a/mlir/lib/Dialect/Quant/IR/TypeParser.cpp b/mlir/lib/Dialect/Quant/IR/TypeParser.cpp index 1a42b90ac31e2..eef152bf49946 100644 --- a/mlir/lib/Dialect/Quant/IR/TypeParser.cpp +++ b/mlir/lib/Dialect/Quant/IR/TypeParser.cpp @@ -48,7 +48,7 @@ static Type parseStorageType(DialectAsmParser &parser, bool &isSigned) { return nullptr; } isSigned = false; - type = parser.getBuilder().getIntegerType(storageTypeWidth); + type = parser.getBuilder().getIntegerType(storageTypeWidth, isSigned); } else { parser.emitError(typeLoc, "illegal storage type prefix"); return nullptr; diff --git a/mlir/test/Dialect/Quant/Bytecode/u8-storage-roundtrip.mlir b/mlir/test/Dialect/Quant/Bytecode/u8-storage-roundtrip.mlir new file mode 100644 index 0000000000000..0206788eac725 --- /dev/null +++ b/mlir/test/Dialect/Quant/Bytecode/u8-storage-roundtrip.mlir @@ -0,0 +1,14 @@ +// Verify that the u8 keyword in quant types creates unsigned (ui8) storage, +// not signless (i8). The quant printer always outputs "u8" regardless of the +// underlying IntegerType signedness, so the only way to detect a mismatch is +// to compare bytecodes: one from the explicit "ui8" syntax (parsed via +// parseOptionalType, always unsigned) and one from a text roundtrip through +// the "u8" keyword path. + +// RUN: mlir-opt %s -allow-unregistered-dialect --strip-debuginfo -emit-bytecode -o %t.bc +// RUN: mlir-opt %t.bc -allow-unregistered-dialect | mlir-opt -allow-unregistered-dialect --strip-debuginfo -emit-bytecode -o %t2.bc +// RUN: cmp %t.bc %t2.bc + +module @u8StorageRoundtrip attributes { + bytecode.test = !quant.uniform +} {}