[Mlir-commits] [mlir] [mlir][LLVMIR] Check number of elements in `mlir.constant` verifier (PR #102906)

Andrzej WarzyƄski llvmlistbot at llvm.org
Mon Aug 12 10:31:44 PDT 2024


================
@@ -2728,13 +2740,30 @@ LogicalResult LLVM::ConstantOp::verify() {
     if (isa<IntegerType>(getType()) && !getType().isInteger(floatWidth)) {
       return emitOpError() << "expected integer type of width " << floatWidth;
     }
-  }
-  if (auto splatAttr = dyn_cast<SplatElementsAttr>(getValue())) {
-    if (!isa<VectorType>(getType()) && !isa<LLVM::LLVMArrayType>(getType()) &&
-        !isa<LLVM::LLVMFixedVectorType>(getType()) &&
-        !isa<LLVM::LLVMScalableVectorType>(getType()))
+  } else if (isa<ElementsAttr, ArrayAttr>(getValue())) {
+    if (isa<LLVM::LLVMScalableVectorType>(getType())) {
----------------
banach-space wrote:

I've looked at this in a slightly different context recently. My recommendation is to only allow "splats" when dealing with scalable vectors. As in, this would be fine:
```mlir
llvm.mlir.constant(dense<[0]> : vector<[4]xi32>)
```
but not this:
```mlir
llvm.mlir.constant(dense<[0, 1, 2, 3]> : vector<[4]xi32>)
```

I don't envisage us requiring the 2nd option.

https://github.com/llvm/llvm-project/pull/102906


More information about the Mlir-commits mailing list