Skip to content

Commit

Permalink
[mlir][sparse] made sparse vectorizer more robust on position of inva…
Browse files Browse the repository at this point in the history
…riants (llvm#80766)

Because the sparse vectorizer relies on the code coming out of the
sparsifier, the "patterns" are not always made very general. However, a
recent change in the generated code revealed an obvious situation where
the subscript analysis could be made a bit more robust.

Fixes:
llvm#79897
  • Loading branch information
aartbik authored Feb 6, 2024
1 parent dbed898 commit 5a9af39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ static bool vectorizeSubscripts(PatternRewriter &rewriter, scf::ForOp forOp,
if (auto load = cast.getDefiningOp<arith::AddIOp>()) {
Value inv = load.getOperand(0);
Value idx = load.getOperand(1);
// Swap non-invariant.
if (!isInvariantValue(inv, block)) {
inv = idx;
idx = load.getOperand(0);
}
// Inspect.
if (isInvariantValue(inv, block)) {
if (auto arg = llvm::dyn_cast<BlockArgument>(idx)) {
if (isInvariantArg(arg, block) || !innermost)
Expand Down
3 changes: 1 addition & 2 deletions mlir/test/Dialect/SparseTensor/sparse_vector_mv.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// FIXME: re-enable.
// RUN: mlir-opt %s -sparsifier="vl=8" | FileCheck %s

#Dense = #sparse_tensor.encoding<{
Expand All @@ -16,7 +15,7 @@
}

// CHECK-LABEL: llvm.func @kernel_matvec
// C_HECK: llvm.intr.vector.reduce.fadd
// CHECK: llvm.intr.vector.reduce.fadd
func.func @kernel_matvec(%arga: tensor<?x?xf32, #Dense>,
%argb: tensor<?xf32>,
%argx: tensor<?xf32>) -> tensor<?xf32> {
Expand Down

0 comments on commit 5a9af39

Please sign in to comment.