[Mlir-commits] [mlir] [mlir][Vector] Add `vector.shuffle` fold for poison inputs (PR #125608)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Feb 5 00:19:45 PST 2025


================
@@ -2684,25 +2682,45 @@ OpFoldResult vector::ShuffleOp::fold(FoldAdaptor adaptor) {
   if (!v1Attr || !v2Attr)
     return {};
 
+  // Fold shuffle poison, poison -> poison.
+  bool isV1Poison = isa<ub::PoisonAttr>(v1Attr);
+  bool isV2Poison = isa<ub::PoisonAttr>(v2Attr);
+  if (isV1Poison && isV2Poison)
+    return ub::PoisonAttr::get(getContext());
+
   // Only support 1-D for now to avoid complicated n-D DenseElementsAttr
   // manipulation.
   if (v1Type.getRank() != 1)
     return {};
 
-  int64_t v1Size = v1Type.getDimSize(0);
+  // Poison input attributes need special handling as they are not
+  // DenseElementsAttr. If an index is poison, we select the first element of
+  // the first non-poison input.
----------------
banach-space wrote:

> It's valid to substitute poison with an arbitrary value

Sure, but we are selecting a specific "arbitrary value" :)

> Not sure I follow the prior-art part.

I was just curious whether there's any rationale behind this specific option. For example, something else in LLVM or MLIR makes similar choice?

Basically, what I'm missing is "why would we select the first element"? Something along the lines would be helpful:
> I doesn't matter what we select, but we need to make a choice. We choose the first element.

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


More information about the Mlir-commits mailing list