Skip to content

[mlir] Canonicalizer crashed in AffineForEmptyLoopFolder::matchAndRewrite with assertion failure "must be defined outside of the loop". #74301

@ghost

Description

git version: e9c6f3f

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: mlir-opt --canonicalize a.mlir

a.mlir:

func.func private @func2() {
  %cst_12 = arith.constant dense<23> : vector<15xindex>
  %cst_13 = arith.constant dense<false> : vector<15xi1>
  %cst_18 = arith.constant 1.000000e+00 : f16
  %c0 = arith.constant 0 : index
  %c7 = arith.constant 7 : index
  %c18 = arith.constant 18 : index
  %alloc_27 = memref.alloc(%c18, %c7) : memref<?x?xf16>
  %10 = affine.for %arg3 = 0 to 114 iter_args(%arg4 = %c18) -> (index) {
    affine.yield %arg3 : index
  }
  %13 = memref.alloca_scope  -> (f16) {
    memref.alloca_scope.return %cst_18 : f16
  }
  memref.alloca_scope  {
    %16 = vector.broadcast %13 : f16 to vector<15xf16>
    vector.scatter %alloc_27[%10, %c0] [%cst_12], %cst_13, %16 : memref<?x?xf16>, vector<15xindex>, vector<15xi1>, vector<15xf16>
  }
  return
}

trace:

mlir-opt: /data/bin/llvm-project/mlir/lib/Dialect/Affine/IR/AffineOps.cpp:2276: virtual mlir::LogicalResult {anonymous}::AffineForEmptyLoopFolder::matchAndRewrite(mlir::affine::AffineForOp, mlir::PatternRewriter&) const: Assertion `forOp.isDefinedOutsideOfLoop(val) && "must be defined outside of the loop"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/bin/llvm-project/build/bin/mlir-opt --inline a.mlir
 #0 0x0000555f2494de6f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x1640e6f)
 #1 0x0000555f2494aec4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f1f6f4ae420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f1f6ef9900b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f1f6ef78859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f1f6ef78729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f1f6ef89fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000555f24a3ee91 (anonymous namespace)::AffineForEmptyLoopFolder::matchAndRewrite(mlir::affine::AffineForOp, mlir::PatternRewriter&) const AffineOps.cpp:0:0
 #8 0x0000555f2a3021d8 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&)>) (/data/bin/llvm-project/build/bin/mlir-opt+0x6ff51d8)
 #9 0x0000555f276759fc (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#10 0x0000555f27679e6b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x436ce6b)
#11 0x0000555f275df13a (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#12 0x0000555f275c008e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b308e)
#13 0x0000555f275c056a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b356a)
#14 0x0000555f275c1633 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult (mlir::OpPassManager&, mlir::Operation*)>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::'lambda'(mlir::OpPassManager&, mlir::Operation*)>(long, mlir::OpPassManager&, mlir::Operation*) Pass.cpp:0:0
#15 0x0000555f275ef323 (anonymous namespace)::InlinerPass::optimizeCallable(mlir::CallGraphNode*, llvm::StringMap<mlir::OpPassManager, llvm::MallocAllocator>&) Inliner.cpp:0:0
#16 0x0000555f275f8256 mlir::LogicalResult llvm::function_ref<mlir::LogicalResult ((anonymous namespace)::CallGraphSCC&)>::callback_fn<(anonymous namespace)::InlinerPass::runOnOperation()::'lambda'((anonymous namespace)::CallGraphSCC&)>(long, (anonymous namespace)::CallGraphSCC&) Inliner.cpp:0:0
#17 0x0000555f275f9043 (anonymous namespace)::InlinerPass::runOnOperation() Inliner.cpp:0:0
#18 0x0000555f275c008e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b308e)
#19 0x0000555f275c056a mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b356a)
#20 0x0000555f275c0d94 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x42b3d94)
#21 0x0000555f275b1b03 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#22 0x0000555f275b2fd4 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#23 0x0000555f275b3184 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&) MlirOptMain.cpp:0:0
#24 0x0000555f276b2474 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&, bool, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x43a5474)
#25 0x0000555f275ab9e7 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x429e9e7)
#26 0x0000555f275b32d1 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x42a62d1)
#27 0x0000555f275b3736 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x42a6736)
#28 0x0000555f248854eb main (/data/bin/llvm-project/build/bin/mlir-opt+0x15784eb)
#29 0x00007f1f6ef7a083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#30 0x0000555f2491e1ce _start (/data/bin/llvm-project/build/bin/mlir-opt+0x16111ce)
Aborted (core dumped)

Metadata

Metadata

Assignees

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]mlir:affine

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions