[Mlir-commits] [mlir] [mlirbc] Fix incorrect skipping for single byte blob. (PR #182445)
Jacques Pienaar
llvmlistbot at llvm.org
Thu Feb 19 23:03:10 PST 2026
https://github.com/jpienaar created https://github.com/llvm/llvm-project/pull/182445
This resulted in not correctly unpacking. Added additional regression tests.
>From c896f4d8faf9f0762925ba2f39bd1412b442b07d Mon Sep 17 00:00:00 2001
From: Jacques Pienaar <jacques+gh at japienaar.info>
Date: Fri, 20 Feb 2026 07:01:14 +0000
Subject: [PATCH] [mlirbc] Fix incorrect skipping for single byte blob.
This resulted in not correctly unpacking. Added additional regression
tests.
---
mlir/lib/IR/BuiltinDialectBytecode.cpp | 5 +--
mlir/test/Bytecode/i1_roundtrip.mlir | 45 ++++++++++++++++++++++
mlir/test/Bytecode/i1_splat_roundtrip.mlir | 17 --------
3 files changed, 47 insertions(+), 20 deletions(-)
create mode 100644 mlir/test/Bytecode/i1_roundtrip.mlir
delete mode 100644 mlir/test/Bytecode/i1_splat_roundtrip.mlir
diff --git a/mlir/lib/IR/BuiltinDialectBytecode.cpp b/mlir/lib/IR/BuiltinDialectBytecode.cpp
index a87224a48c32a..8cf25391ba11a 100644
--- a/mlir/lib/IR/BuiltinDialectBytecode.cpp
+++ b/mlir/lib/IR/BuiltinDialectBytecode.cpp
@@ -168,12 +168,11 @@ readDenseIntOrFPElementsAttr(DialectBytecodeReader &reader, ShapedType type,
// cheap.
size_t numElements = type.getNumElements();
size_t packedSize = llvm::divideCeil(numElements, 8);
- if (blob.size() == packedSize && blob.size() != numElements &&
- blob.size() != 1) {
+ if (blob.size() == packedSize && blob.size() != numElements) {
// Unpack the blob.
rawData.resize(numElements);
for (size_t i = 0; i < numElements; ++i)
- rawData[i] = (blob[i / 8] & (1 << (i % 8))) ? 0xFF : 0x00;
+ rawData[i] = (blob[i / 8] & (1 << (i % 8))) ? 1 : 0;
return success();
}
// Otherwise, fallback to the default behavior.
diff --git a/mlir/test/Bytecode/i1_roundtrip.mlir b/mlir/test/Bytecode/i1_roundtrip.mlir
new file mode 100644
index 0000000000000..dc2529e62430e
--- /dev/null
+++ b/mlir/test/Bytecode/i1_roundtrip.mlir
@@ -0,0 +1,45 @@
+// RUN: mlir-opt %s -emit-bytecode | mlir-opt | FileCheck %s
+
+// CHECK-LABEL: func.func @test_i1_splat_true
+func.func @test_i1_splat_true() -> tensor<100xi1> {
+// CHECK: arith.constant dense<true> : tensor<100xi1>
+ %0 = arith.constant dense<true> : tensor<100xi1>
+ return %0 : tensor<100xi1>
+}
+
+
+// CHECK-LABEL: func.func @test_i1_splat_false
+func.func @test_i1_splat_false() -> tensor<100xi1> {
+// CHECK: arith.constant dense<false> : tensor<100xi1>
+ %0 = arith.constant dense<false> : tensor<100xi1>
+ return %0 : tensor<100xi1>
+}
+
+
+// CHECK-LABEL: func.func @test_8xi1_splat_true
+func.func @test_8xi1_splat_true() -> tensor<8xi1> {
+// CHECK: arith.constant dense<true> : tensor<8xi1>
+ %0 = arith.constant dense<true> : tensor<8xi1>
+ return %0 : tensor<8xi1>
+}
+
+// CHECK-LABEL: func.func @test_8xi1_splat_false
+func.func @test_8xi1_splat_false() -> tensor<8xi1> {
+// CHECK: arith.constant dense<false> : tensor<8xi1>
+ %0 = arith.constant dense<false> : tensor<8xi1>
+ return %0 : tensor<8xi1>
+}
+
+// CHECK-LABEL: func.func @test_i8_mixed()
+func.func @test_i8_mixed() {
+ // CHECK: arith.constant dense<[true, false, true, false, true, false, true, false]> : tensor<8xi1>
+ %0 = arith.constant dense<[true, false, true, false, true, false, true, false]> : tensor<8xi1>
+ return
+}
+
+// CHECK-LABEL: func.func @test_i9_mixed()
+func.func @test_i9_mixed() {
+ // CHECK: arith.constant dense<[true, false, true, false, true, false, true, false, true]> : tensor<9xi1>
+ %0 = arith.constant dense<[true, false, true, false, true, false, true, false, true]> : tensor<9xi1>
+ return
+}
diff --git a/mlir/test/Bytecode/i1_splat_roundtrip.mlir b/mlir/test/Bytecode/i1_splat_roundtrip.mlir
deleted file mode 100644
index dde6fe61934e6..0000000000000
--- a/mlir/test/Bytecode/i1_splat_roundtrip.mlir
+++ /dev/null
@@ -1,17 +0,0 @@
-// RUN: mlir-opt %s -emit-bytecode | mlir-opt | FileCheck %s
-
-func.func @test_i1_splat_true() -> tensor<100xi1> {
- %0 = arith.constant dense<true> : tensor<100xi1>
- return %0 : tensor<100xi1>
-}
-
-// CHECK-LABEL: func.func @test_i1_splat_true
-// CHECK: arith.constant dense<true> : tensor<100xi1>
-
-func.func @test_i1_splat_false() -> tensor<100xi1> {
- %0 = arith.constant dense<false> : tensor<100xi1>
- return %0 : tensor<100xi1>
-}
-
-// CHECK-LABEL: func.func @test_i1_splat_false
-// CHECK: arith.constant dense<false> : tensor<100xi1>
More information about the Mlir-commits
mailing list