[Mlir-commits] [mlir] 8a9f362 - [MLIR][Arith] Ensure ConstantOp validates signless integers for vectors (#177857)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Jan 29 05:01:03 PST 2026
Author: Miloš Poletanović
Date: 2026-01-29T08:00:58-05:00
New Revision: 8a9f362e5151470a319c63c06867790a08eef488
URL: https://github.com/llvm/llvm-project/commit/8a9f362e5151470a319c63c06867790a08eef488
DIFF: https://github.com/llvm/llvm-project/commit/8a9f362e5151470a319c63c06867790a08eef488.diff
LOG: [MLIR][Arith] Ensure ConstantOp validates signless integers for vectors (#177857)
Fixes #177818
`arith::ConstantOp::isBuildableWith()` was only checking scalar integers
for signlessness, allowing signed vector element types to pass
validation incorrectly.
---------
Co-authored-by: Milos Poletanovic <mpoletanovic at syrmia.com>
Added:
mlir/test/Conversion/SCFToSPIRV/signed-vector.mlir
Modified:
mlir/lib/Dialect/Arith/IR/ArithOps.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index c61bd01fd5e9b..83b3cec8d41af 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -235,9 +235,10 @@ bool arith::ConstantOp::isBuildableWith(Attribute value, Type type) {
if (!typedAttr || typedAttr.getType() != type)
return false;
// Integer values must be signless.
- if (llvm::isa<IntegerType>(type) &&
- !llvm::cast<IntegerType>(type).isSignless())
- return false;
+ if (auto intType = dyn_cast<IntegerType>(getElementTypeOrSelf(type))) {
+ if (!intType.isSignless())
+ return false;
+ }
// Integer, float, and element attributes are buildable.
return llvm::isa<IntegerAttr, FloatAttr, ElementsAttr>(value);
}
diff --git a/mlir/test/Conversion/SCFToSPIRV/signed-vector.mlir b/mlir/test/Conversion/SCFToSPIRV/signed-vector.mlir
new file mode 100644
index 0000000000000..ebba34d57e36f
--- /dev/null
+++ b/mlir/test/Conversion/SCFToSPIRV/signed-vector.mlir
@@ -0,0 +1,12 @@
+// RUN: mlir-opt -convert-scf-to-spirv %s | FileCheck %s
+
+// CHECK-LABEL: spirv.func @main() "None" {
+// CHECK: %[[VAL_0:.*]] = spirv.Constant -5 : si32
+// CHECK: %[[FROM_ELEMENTS_0:.*]] = vector.from_elements %[[VAL_0]] : vector<1xsi32>
+// CHECK: spirv.Return
+func.func @main() {
+ %2 = spirv.Constant -5 : si32
+ %3 = vector.from_elements %2 : vector<1xsi32>
+ return
+}
+
More information about the Mlir-commits
mailing list