llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.77k stars 10.97k forks source link

[MLIR][Linalg] Vectorization Fail with reduction #97247

Open CoTinker opened 4 days ago

CoTinker commented 4 days ago

Such linalg.generic can not be vetorized:

// mlir-opt test.mlir -transform-interpreter
#map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)>
#map1 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)>
module {
  func.func @generic_1_12_197_197_1_12_197_1_f32_547(%arg0: memref<1x12x197x197xf32>, %arg1: memref<1x12x197x1xf32>) attributes {global_kernel = ""} {
    linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel", "reduction"]} ins(%arg0 : memref<1x12x197x197xf32>) outs(%arg1 : memref<1x12x197x1xf32>) {
    ^bb0(%in: f32, %out: f32):
      %0 = arith.addf %in, %out : f32
      linalg.yield %0 : f32
    }
    return
  }
  module attributes {transform.with_named_sequence} {
    transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) {
      %0 = transform.structured.match ops{["linalg.generic"]} in %arg0 : (!transform.any_op) -> !transform.any_op
      %1 = transform.get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op
      %2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op
      transform.yield
    }
  }
}

It’s report:

mlir-opt: llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:475: mlir::AffineMap reindexIndexingMap(mlir::AffineMap): Assertion `res.getNumDims() == res.getNumResults() && "expected reindexed map with same number of dims and results"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ../compiler/bin/mlir-opt --transform-interpreter test.mlir
 #0 0x0000559a97de75e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/mls/community/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x0000559a97de7a05 PrintStackTraceSignalHandler(void*) /home/mls/community/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x0000559a97de4e55 llvm::sys::RunSignalHandlers() /home/mls/community/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x0000559a97de6e7c SignalHandler(int) /home/mls/community/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f87452ad520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #5 0x00007f87453019fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f87453019fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x00007f87453019fc pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x00007f87452ad476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x00007f87452937f3 abort ./stdlib/abort.c:81:7
#10 0x00007f874529371b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x00007f87452a4e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#12 0x0000559a998ef6ea reindexIndexingMap(mlir::AffineMap) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:477:10
#13 0x0000559a998f3eb1 vectorizeAsLinalgGeneric(mlir::RewriterBase&, VectorizationState&, mlir::linalg::LinalgOp, llvm::SmallVectorImpl<mlir::Value>&) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:1334:35
#14 0x0000559a99901c59 auto mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool)::'lambda'(auto)::operator()<mlir::linalg::LinalgOp>(auto) const /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:2064:79
#15 0x0000559a99901ced llvm::TypeSwitch<mlir::Operation*, mlir::LogicalResult>& llvm::TypeSwitch<mlir::Operation*, mlir::LogicalResult>::Case<mlir::linalg::LinalgOp, mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool)::'lambda'(auto)>(mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool)::'lambda'(auto)&&) /home/mls/community/llvm-project/llvm/include/llvm/ADT/TypeSwitch.h:102:28
#16 0x0000559a998f8a38 mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:2036:34
#17 0x0000559a99346b2a (anonymous namespace)::VectorizationPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:3309:21
#18 0x0000559aa1b2686a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::'lambda'()::operator()() const /home/mls/community/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:212:46
#19 0x0000559aa1b2722f void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::'lambda'()>(long) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#20 0x0000559a97e0a872 llvm::function_ref<void ()>::operator()() const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#21 0x0000559aa1b2a63f void mlir::MLIRContext::executeAction<mlir::ApplyPatternAction, mlir::Pattern const&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pattern const&) /home/mls/community/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#22 0x0000559aa1b26fdc mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/mls/community/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:233:5
#23 0x0000559a9d57d0ae (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:615:32
#24 0x0000559a9d57e252 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::'lambda2'()::operator()() const /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:874:28
#25 0x0000559a9d57f4a6 void llvm::function_ref<void ()>::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::'lambda2'()>(long) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#26 0x0000559a97e0a872 llvm::function_ref<void ()>::operator()() const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#27 0x0000559a9d57f1ef void mlir::MLIRContext::executeAction<(anonymous namespace)::GreedyPatternRewriteIteration, long&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, long&) /home/mls/community/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#28 0x0000559a9d57e545 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) && /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:887:3
#29 0x0000559a9d57e69a mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:919:55
#30 0x0000559a97fe66b6 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/mls/community/llvm-project/mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:159:37
#31 0x0000559a99346ffb mlir::transform::VectorizeChildrenAndApplyPatternsOp::applyToOne(mlir::transform::TransformRewriter&, mlir::Operation*, mlir::transform::ApplyToEachResultList&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:3364:13
#32 0x0000559a9929d4a2 mlir::DiagnosedSilenceableFailure mlir::transform::detail::applyTransformToEach<mlir::transform::VectorizeChildrenAndApplyPatternsOp, llvm::iterator_range<llvm::filter_iterator_impl<mlir::Operation* const*, mlir::transform::TransformState::getPayloadOps(mlir::Value) const::'lambda'(mlir::Operation*), std::bidirectional_iterator_tag>>&>(mlir::transform::VectorizeChildrenAndApplyPatternsOp, mlir::transform::TransformRewriter&, llvm::iterator_range<llvm::filter_iterator_impl<mlir::Operation* const*, mlir::transform::TransformState::getPayloadOps(mlir::Value) const::'lambda'(mlir::Operation*), std::bidirectional_iterator_tag>>&, llvm::SmallVectorImpl<mlir::transform::ApplyToEachResultList>&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h:1510:30
#33 0x0000559a992928d3 mlir::transform::TransformEachOpTrait<mlir::transform::VectorizeChildrenAndApplyPatternsOp>::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h:1584:31
#34 0x0000559a992862f8 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::VectorizeChildrenAndApplyPatternsOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:478:1
#35 0x0000559aa1ad648c mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:62:3
#36 0x0000559aa1acf020 mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:955:19
#37 0x0000559a9bd3cc10 applySequenceBlock(mlir::Block&, mlir::transform::FailurePropagationMode, mlir::transform::TransformState&, mlir::transform::TransformResults&) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:1789:33
#38 0x0000559a9bd3f77a mlir::transform::NamedSequenceOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:2157:1
#39 0x0000559a9bca69c0 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::NamedSequenceOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:478:1
#40 0x0000559aa1ad648c mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:62:3
#41 0x0000559aa1acf020 mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:955:19
#42 0x0000559aa1ad60b5 mlir::transform::applyTransforms(mlir::Operation*, mlir::transform::TransformOpInterface, mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>> const&, mlir::transform::TransformOptions const&, bool) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:2017:56
#43 0x0000559a9bdc2ba8 mlir::transform::applyTransformNamedSequence(mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>>, mlir::transform::TransformOpInterface, mlir::ModuleOp, mlir::transform::TransformOptions const&) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp:234:25
#44 0x0000559a9bdb9c6f (anonymous namespace)::InterpreterPass::runOnOperation() /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Transforms/InterpreterPass.cpp:147:15
#45 0x0000559a9d459d19 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda0'()::operator()() const /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:524:57
#46 0x0000559a9d45d9fc void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda0'()>(long) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40
#47 0x0000559a97e0a872 llvm::function_ref<void ()>::operator()() const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62
#48 0x0000559a9d464f57 void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/mls/community/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3
#49 0x0000559a9d45a13b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:533:23
#50 0x0000559a9d45a416 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:593:15
#51 0x0000559a9d45c342 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:904:40
#52 0x0000559a9d45c19a mlir::PassManager::run(mlir::Operation*) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:884:69
#53 0x0000559a9d44c9c8 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:409:13
#54 0x0000559a9d44d0ae processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:474:26
#55 0x0000559a9d44d673 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:549:25
#56 0x0000559a9d44e7b7 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:52
#57 0x0000559a9d5e9351 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12
#58 0x0000559a9d5e8be2 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /home/mls/community/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:30
#59 0x0000559a9d44d7ed mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:31
#60 0x0000559a9d44dac7 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:590:13
#61 0x0000559a9d44dcbe mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:606:21
#62 0x0000559a97d44a27 main /home/mls/community/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:311:0
#63 0x00007f8745294d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#64 0x00007f8745294e40 call_init ./csu/../csu/libc-start.c:128:20
#65 0x00007f8745294e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#66 0x0000559a97d444e5 _start (../compiler/bin/mlir-opt+0x1da74e5)
Aborted (core dumped)

I know the error is because the compressed dimension is not equal to the result dimension, but I don’t know how to fix it. https://github.com/llvm/llvm-project/blob/bf536cc7db1b1e683af34f363f62fa2b655262cf/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L471-L478

CoTinker commented 4 days ago

CC @dcaballe @ftynse

llvmbot commented 4 days ago

@llvm/issue-subscribers-mlir-linalg

Author: Longsheng Mou (CoTinker)

Such linalg.generic can not be vetorized: ``` // mlir-opt test.mlir -transform-interpreter #map = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, d3)> #map1 = affine_map<(d0, d1, d2, d3) -> (d0, d1, d2, 0)> module { func.func @generic_1_12_197_197_1_12_197_1_f32_547(%arg0: memref<1x12x197x197xf32>, %arg1: memref<1x12x197x1xf32>) attributes {global_kernel = ""} { linalg.generic {indexing_maps = [#map, #map1], iterator_types = ["parallel", "parallel", "parallel", "reduction"]} ins(%arg0 : memref<1x12x197x197xf32>) outs(%arg1 : memref<1x12x197x1xf32>) { ^bb0(%in: f32, %out: f32): %0 = arith.addf %in, %out : f32 linalg.yield %0 : f32 } return } module attributes {transform.with_named_sequence} { transform.named_sequence @__transform_main(%arg0: !transform.any_op {transform.readonly}) { %0 = transform.structured.match ops{["linalg.generic"]} in %arg0 : (!transform.any_op) -> !transform.any_op %1 = transform.get_parent_op %0 {isolated_from_above} : (!transform.any_op) -> !transform.any_op %2 = transform.structured.vectorize_children_and_apply_patterns %1 : (!transform.any_op) -> !transform.any_op transform.yield } } } ``` It’s report: ``` mlir-opt: llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:475: mlir::AffineMap reindexIndexingMap(mlir::AffineMap): Assertion `res.getNumDims() == res.getNumResults() && "expected reindexed map with same number of dims and results"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: ../compiler/bin/mlir-opt --transform-interpreter test.mlir #0 0x0000559a97de75e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/mls/community/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22 #1 0x0000559a97de7a05 PrintStackTraceSignalHandler(void*) /home/mls/community/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1 #2 0x0000559a97de4e55 llvm::sys::RunSignalHandlers() /home/mls/community/llvm-project/llvm/lib/Support/Signals.cpp:105:20 #3 0x0000559a97de6e7c SignalHandler(int) /home/mls/community/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1 #4 0x00007f87452ad520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #5 0x00007f87453019fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #6 0x00007f87453019fc __pthread_kill_internal ./nptl/pthread_kill.c:78:10 #7 0x00007f87453019fc pthread_kill ./nptl/pthread_kill.c:89:10 #8 0x00007f87452ad476 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #9 0x00007f87452937f3 abort ./stdlib/abort.c:81:7 #10 0x00007f874529371b _nl_load_domain ./intl/loadmsgcat.c:1177:9 #11 0x00007f87452a4e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #12 0x0000559a998ef6ea reindexIndexingMap(mlir::AffineMap) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:477:10 #13 0x0000559a998f3eb1 vectorizeAsLinalgGeneric(mlir::RewriterBase&, VectorizationState&, mlir::linalg::LinalgOp, llvm::SmallVectorImpl<mlir::Value>&) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:1334:35 #14 0x0000559a99901c59 auto mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool)::'lambda'(auto)::operator()<mlir::linalg::LinalgOp>(auto) const /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:2064:79 #15 0x0000559a99901ced llvm::TypeSwitch<mlir::Operation*, mlir::LogicalResult>& llvm::TypeSwitch<mlir::Operation*, mlir::LogicalResult>::Case<mlir::linalg::LinalgOp, mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool)::'lambda'(auto)>(mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool)::'lambda'(auto)&&) /home/mls/community/llvm-project/llvm/include/llvm/ADT/TypeSwitch.h:102:28 #16 0x0000559a998f8a38 mlir::linalg::vectorize(mlir::RewriterBase&, mlir::Operation*, llvm::ArrayRef<long>, llvm::ArrayRef<bool>, bool, bool) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp:2036:34 #17 0x0000559a99346b2a (anonymous namespace)::VectorizationPattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:3309:21 #18 0x0000559aa1b2686a mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::'lambda'()::operator()() const /home/mls/community/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:212:46 #19 0x0000559aa1b2722f void llvm::function_ref<void ()>::callback_fn<mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>)::'lambda'()>(long) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40 #20 0x0000559a97e0a872 llvm::function_ref<void ()>::operator()() const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62 #21 0x0000559aa1b2a63f void mlir::MLIRContext::executeAction<mlir::ApplyPatternAction, mlir::Pattern const&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pattern const&) /home/mls/community/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3 #22 0x0000559aa1b26fdc mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) /home/mls/community/llvm-project/mlir/lib/Rewrite/PatternApplicator.cpp:233:5 #23 0x0000559a9d57d0ae (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:615:32 #24 0x0000559a9d57e252 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::'lambda2'()::operator()() const /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:874:28 #25 0x0000559a9d57f4a6 void llvm::function_ref<void ()>::callback_fn<(anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) &&::'lambda2'()>(long) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40 #26 0x0000559a97e0a872 llvm::function_ref<void ()>::operator()() const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62 #27 0x0000559a9d57f1ef void mlir::MLIRContext::executeAction<(anonymous namespace)::GreedyPatternRewriteIteration, long&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, long&) /home/mls/community/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3 #28 0x0000559a9d57e545 (anonymous namespace)::RegionPatternRewriteDriver::simplify(bool*) && /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:887:3 #29 0x0000559a9d57e69a mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/mls/community/llvm-project/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp:919:55 #30 0x0000559a97fe66b6 mlir::applyPatternsAndFoldGreedily(mlir::Operation*, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) /home/mls/community/llvm-project/mlir/include/mlir/Transforms/GreedyPatternRewriteDriver.h:159:37 #31 0x0000559a99346ffb mlir::transform::VectorizeChildrenAndApplyPatternsOp::applyToOne(mlir::transform::TransformRewriter&, mlir::Operation*, mlir::transform::ApplyToEachResultList&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:3364:13 #32 0x0000559a9929d4a2 mlir::DiagnosedSilenceableFailure mlir::transform::detail::applyTransformToEach<mlir::transform::VectorizeChildrenAndApplyPatternsOp, llvm::iterator_range<llvm::filter_iterator_impl<mlir::Operation* const*, mlir::transform::TransformState::getPayloadOps(mlir::Value) const::'lambda'(mlir::Operation*), std::bidirectional_iterator_tag>>&>(mlir::transform::VectorizeChildrenAndApplyPatternsOp, mlir::transform::TransformRewriter&, llvm::iterator_range<llvm::filter_iterator_impl<mlir::Operation* const*, mlir::transform::TransformState::getPayloadOps(mlir::Value) const::'lambda'(mlir::Operation*), std::bidirectional_iterator_tag>>&, llvm::SmallVectorImpl<mlir::transform::ApplyToEachResultList>&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h:1510:30 #33 0x0000559a992928d3 mlir::transform::TransformEachOpTrait<mlir::transform::VectorizeChildrenAndApplyPatternsOp>::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h:1584:31 #34 0x0000559a992862f8 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::VectorizeChildrenAndApplyPatternsOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:478:1 #35 0x0000559aa1ad648c mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:62:3 #36 0x0000559aa1acf020 mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:955:19 #37 0x0000559a9bd3cc10 applySequenceBlock(mlir::Block&, mlir::transform::FailurePropagationMode, mlir::transform::TransformState&, mlir::transform::TransformResults&) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:1789:33 #38 0x0000559a9bd3f77a mlir::transform::NamedSequenceOp::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/IR/TransformOps.cpp:2157:1 #39 0x0000559a9bca69c0 mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Model<mlir::transform::NamedSequenceOp>::apply(mlir::transform::detail::TransformOpInterfaceInterfaceTraits::Concept const*, mlir::Operation*, mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.h.inc:478:1 #40 0x0000559aa1ad648c mlir::transform::TransformOpInterface::apply(mlir::transform::TransformRewriter&, mlir::transform::TransformResults&, mlir::transform::TransformState&) /home/mls/community/build-llvm/tools/mlir/include/mlir/Dialect/Transform/Interfaces/TransformInterfaces.cpp.inc:62:3 #41 0x0000559aa1acf020 mlir::transform::TransformState::applyTransform(mlir::transform::TransformOpInterface) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:955:19 #42 0x0000559aa1ad60b5 mlir::transform::applyTransforms(mlir::Operation*, mlir::transform::TransformOpInterface, mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>> const&, mlir::transform::TransformOptions const&, bool) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp:2017:56 #43 0x0000559a9bdc2ba8 mlir::transform::applyTransformNamedSequence(mlir::RaggedArray<llvm::PointerUnion<mlir::Operation*, mlir::Attribute, mlir::Value>>, mlir::transform::TransformOpInterface, mlir::ModuleOp, mlir::transform::TransformOptions const&) /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Transforms/TransformInterpreterUtils.cpp:234:25 #44 0x0000559a9bdb9c6f (anonymous namespace)::InterpreterPass::runOnOperation() /home/mls/community/llvm-project/mlir/lib/Dialect/Transform/Transforms/InterpreterPass.cpp:147:15 #45 0x0000559a9d459d19 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda0'()::operator()() const /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:524:57 #46 0x0000559a9d45d9fc void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda0'()>(long) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:40 #47 0x0000559a97e0a872 llvm::function_ref<void ()>::operator()() const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:62 #48 0x0000559a9d464f57 void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /home/mls/community/llvm-project/mlir/include/mlir/IR/MLIRContext.h:276:3 #49 0x0000559a9d45a13b mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:533:23 #50 0x0000559a9d45a416 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:593:15 #51 0x0000559a9d45c342 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:904:40 #52 0x0000559a9d45c19a mlir::PassManager::run(mlir::Operation*) /home/mls/community/llvm-project/mlir/lib/Pass/Pass.cpp:884:69 #53 0x0000559a9d44c9c8 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:409:13 #54 0x0000559a9d44d0ae processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:474:26 #55 0x0000559a9d44d673 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:549:25 #56 0x0000559a9d44e7b7 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:52 #57 0x0000559a9d5e9351 llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /home/mls/community/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:68:12 #58 0x0000559a9d5e8be2 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /home/mls/community/llvm-project/mlir/lib/Support/ToolUtilities.cpp:28:30 #59 0x0000559a9d44d7ed mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:552:31 #60 0x0000559a9d44dac7 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:590:13 #61 0x0000559a9d44dcbe mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /home/mls/community/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:606:21 #62 0x0000559a97d44a27 main /home/mls/community/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:311:0 #63 0x00007f8745294d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #64 0x00007f8745294e40 call_init ./csu/../csu/libc-start.c:128:20 #65 0x00007f8745294e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #66 0x0000559a97d444e5 _start (../compiler/bin/mlir-opt+0x1da74e5) Aborted (core dumped) ``` I know the error is because the compressed dimension is not equal to the result dimension, but I don’t know how to fix it. https://github.com/llvm/llvm-project/blob/bf536cc7db1b1e683af34f363f62fa2b655262cf/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp#L471-L478