[Mlir-commits] [mlir] [WIP][MLIR][Affine] Add vector support to affine.linearize_index and affine.delinearize_index (PR #188369)
Keshav Vinayak Jha
llvmlistbot at llvm.org
Wed Mar 25 08:57:12 PDT 2026
================
@@ -29,19 +31,85 @@ using namespace mlir;
using namespace mlir::affine;
namespace {
+
+/// Create a constant splat of the given type with the given integer value.
+static Value createTypedConstant(OpBuilder &b, Location loc, Type type,
+ int64_t value) {
+ if (auto vecTy = dyn_cast<VectorType>(type))
+ return arith::ConstantOp::create(
+ b, loc, DenseElementsAttr::get(vecTy, b.getIndexAttr(value)));
+ return arith::ConstantIndexOp::create(b, loc, value);
+}
+
+/// Materialize an OpFoldResult (which represents a scalar index or constant)
+/// as a Value matching the given target type. For vector target types, scalar
+/// constants are splatted. Returns failure for dynamic basis with vector types
+/// since that requires vector.broadcast which is not available here.
+static FailureOr<Value> materializeBasis(OpBuilder &b, Location loc,
+ OpFoldResult ofr, Type targetType) {
+ std::optional<int64_t> cst = getConstantIntValue(ofr);
+ if (cst)
+ return createTypedConstant(b, loc, targetType, *cst);
+ // Dynamic scalar basis value. For scalar target types, return as-is.
+ if (isa<IndexType>(targetType))
+ return getValueOrCreateConstantIndexOp(b, loc, ofr);
+ // Dynamic scalar basis with vector target type -- would need
----------------
keshavvinayak01 wrote:
Adding a dependance with vector dialect to support broadcast or `tensor.splat` can handle this case. Not sure if we should do that though.
https://github.com/llvm/llvm-project/pull/188369
More information about the Mlir-commits
mailing list