[Mlir-commits] [mlir] [mlir][Vector] Teach how to materialize UB constant to Vector (PR #125596)

Andrea Faulds llvmlistbot at llvm.org
Tue Feb 4 09:01:49 PST 2025


================
@@ -437,6 +437,9 @@ void VectorDialect::initialize() {
 Operation *VectorDialect::materializeConstant(OpBuilder &builder,
                                               Attribute value, Type type,
                                               Location loc) {
+  if (auto poisonAttr = dyn_cast<ub::PoisonAttrInterface>(value))
+    return builder.create<ub::PoisonOp>(loc, type, poisonAttr);
+
   return arith::ConstantOp::materialize(builder, value, type, loc);
----------------
andfau-amd wrote:

Like you, I am unsure how these are meant to be used. I independently (due to discussion in #125560) tried implementing this before seeing this PR, and I wrote it like this instead:

```cpp
if (isa<ub::PoisonAttr>(value))
    return value.getDialect().materializeConstant(builder, value, type, loc);
```

Both seem to work equally well. Maybe this way is more "consistent"?

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


More information about the Mlir-commits mailing list