[Mlir-commits] [mlir] [mlir][vector] Add vector.step operation (PR #96776)

Cullen Rhodes llvmlistbot at llvm.org
Fri Jul 5 01:51:24 PDT 2024


================
@@ -6316,6 +6316,20 @@ OpFoldResult SplatOp::fold(FoldAdaptor adaptor) {
   return SplatElementsAttr::get(getType(), {constOperand});
 }
 
+//===----------------------------------------------------------------------===//
+// StepOp
+//===----------------------------------------------------------------------===//
+
+OpFoldResult StepOp::fold(FoldAdaptor adaptor) {
+  auto resultType = cast<VectorType>(getType());
+  if (resultType.isScalable())
+    return nullptr;
+  SmallVector<APInt> indices;
+  for (unsigned i = 0; i < resultType.getNumElements(); i++)
+    indices.push_back(APInt(/*width=*/64, i));
+  return DenseElementsAttr::get(resultType, indices);
----------------
c-rhodes wrote:

Purely for convenience to be honest, this seemed like the simplest way to add the op. I know the downside is information is lost when folding to a constant (i.e. it's a constant step of one), as well as consistency as you point out, so am happy to iterate on this if folks would like to see this done differently.

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


More information about the Mlir-commits mailing list