diff --git a/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h b/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h --- a/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h +++ b/mlir/include/mlir/Dialect/SparseTensor/Utils/Merger.h @@ -432,8 +432,15 @@ /// Sets the level number and level-type of the `t`th tensor on /// `i`th loop. void setLevelAndType(TensorId t, LoopId i, Level lvl, DimLevelType dlt) { - assert(t < numTensors && i < numLoops && lvl < lvlToLoop[t].size() && - isValidDLT(dlt)); + assert(t < numTensors && i < numLoops && isValidDLT(dlt)); + // In case with indexing map like (d0) -> (0, d0), there might be more + // levels then loops because of the constant index. + // TODO: Constant indices are currently not support on sparse tensor, but + // are allowed in non-annotated dense tensor. Support it, it would be + // required for sparse tensor slice rank reducing too. + if (lvl >= lvlToLoop[t].size()) + lvlToLoop[t].resize(lvl + 1); + lvlTypes[t][i] = dlt; loopToLvl[t][i] = lvl; lvlToLoop[t][lvl] = i;