[Mlir-commits] [mlir] [MLIR][Arith] Ensure ConstantOp validates signless integers for vectors (PR #177857)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Jan 25 05:57:36 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Miloš Poletanović (milos1397)
<details>
<summary>Changes</summary>
Fixes #<!-- -->177818
`arith::ConstantOp::isBuildableWith()` was only checking scalar integers for signlessness, allowing signed vector element types to pass validation incorrectly.
---
Full diff: https://github.com/llvm/llvm-project/pull/177857.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/Arith/IR/ArithOps.cpp (+5-3)
- (added) mlir/test/Conversion/SCFToSPIRV/signed-vector.mlir (+23)
``````````diff
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 565a537616971..9bc1be7b2e9f1 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -232,9 +232,11 @@ 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;
+ auto elemType = getElementTypeOrSelf(type);
+ if (auto intType = dyn_cast<IntegerType>(elemType)) {
+ 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..7a220e61a56f4
--- /dev/null
+++ b/mlir/test/Conversion/SCFToSPIRV/signed-vector.mlir
@@ -0,0 +1,23 @@
+// NOTE: Assertions have been autogenerated by utils/generate-test-checks.py
+
+// This script is intended to make adding checks to a test case quick and easy.
+// It is *not* authoritative about what constitutes a good test. After using the
+// script, be sure to review and refine the generated checks. For example,
+// CHECK lines should be minimized and named to reflect the test’s intent.
+// For comprehensive guidelines, see:
+// * https://mlir.llvm.org/getting_started/TestingGuide/
+
+module {
+// CHECK-LABEL: spirv.func @main() "None" {
+// CHECK: %[[THREAD_ID_0:.*]] = gpu.thread_id x
+// CHECK: %[[VAL_0:.*]] = spirv.Constant -5 : si32
+// CHECK: %[[FROM_ELEMENTS_0:.*]] = vector.from_elements %[[VAL_0]] : vector<1xsi32>
+// CHECK: spirv.Return
+// CHECK: }
+ func.func @main() {
+ %0 = gpu.thread_id x
+ %2 = spirv.Constant -5 : si32
+ %3 = vector.from_elements %2 : vector<1xsi32>
+ return
+ }
+}
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/177857
More information about the Mlir-commits
mailing list