Help with `ub.poison` and partially poisoned vectors

Hi,

I’m trying to build a partially poisoned vector to use as a mask of a vector.shuffle. The documentation of ub.poison says:

The `poison` operation materializes a compile-time poisoned constant value to
indicate deferred undefined behavior.  `value` attribute is needed to indicate an
optional additional poison semantics (e.g. partially poisoned vectors), default
value indicates resultsis fully poisoned. 

However, I haven’t found any lit test or reference implementation exercising the “value attribute” case upstream. Actually, the PoisonAttrInterface doesn’t seem to have any implementation upstream other than the PoisonAttr default? That got me thinking that perhaps someone has already implemented what I’m looking for downstream, hence this post :).

Specifically, shuffle.vector’s mask is a DenseI64ArrayAttr. Should we make DenseI64ArrayAttr implement the PoisonAttrInterface? Should we introduce a new DensePoisonI64ArrayAttr?

Help appreciated.
Thanks!

CC: @Hardcode84, @kuhar, @mehdi_amini

1 Like

There were some discussions on partially poisoned vectors support but it was never actually implemented. I’m not aware of any downstream work either, but generally +1 to supporting this case.

1 Like

Exactly, this was agreed on but nobody actually implemented it. The op semantics already (mostly) cover elementwise poison values, which we can use to decide validity of fold and canon patterns, but we don’t have any mechanism that would produce elements attr with poison.

There was a prototype implementation linked in one of past threads.

Since then, I have made a newer version that ended up being the one shipped with the project I initially designed the UB dialect for.

It might be more interesting because it is a little saner when it comes to the masking, as it properly provides an ElementsAttr interface over std::optional values. Also, the single-valued poison and poisoned elements (PoisonLike) play nicer together.

Thanks for the information! Would anyone be willing to help with supporting this? I’m not sure I totally follow the context or what the next steps would be but this would be a great to have!