llvm / Polygeist

C/C++ frontend for MLIR. Also features polyhedral optimizations, parallel optimizations, and more!
https://polygeist.llvm.org
Other
493 stars 120 forks source link

Crash when lowering to LLVM #356

Open jabcross opened 1 year ago

jabcross commented 1 year ago

Am I doing something wrong? The function I'm trying to lower was was raised from C by cgeist, and manipulated. In this case, I'm doing constant propagation on one of the parameters.

Commit: fd4194b099ef

Input: (test.mlir)

module {
  func.func @addN_baked_4(%arg0: memref<1xi32>, %arg1: memref<1xi32>) {
    %c4_i32 = arith.constant 4 : i32
    %0 = affine.load %arg0[0] : memref<1xi32>
    %1 = arith.addi %0, %c4_i32 : i32
    affine.store %1, %arg1[0] : memref<1xi32>
    return
  }
}

Command: polygeist-opt --convert-polygeist-to-llvm test.mlir

Dump:

```polygeist-opt: /home/jabcross/repos/llvm-project/mlir/include/mlir/IR/Value.h:430: mlir::detail::TypedValue::TypedValue(mlir::Value) [with Ty = mlir::MemRefType]: Assertion `!val || val.getType().template isa()' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: /home/jabcross/repos/Polygeist/build/bin/polygeist-opt --convert-polygeist-to-llvm test.mlir #0 0x000055e2dbaf8b84 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0 #1 0x000055e2dbaf5fab SignalHandler(int) Signals.cpp:0:0 #2 0x00007f8236e3e710 (/usr/lib/libc.so.6+0x3e710) #3 0x00007f8236e8e83c (/usr/lib/libc.so.6+0x8e83c) #4 0x00007f8236e3e668 gsignal (/usr/lib/libc.so.6+0x3e668) #5 0x00007f8236e264b8 abort (/usr/lib/libc.so.6+0x264b8) #6 0x00007f8236e263dc (/usr/lib/libc.so.6+0x263dc) #7 0x00007f8236e36d26 (/usr/lib/libc.so.6+0x36d26) #8 0x000055e2da233dc2 (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x13ddc2) #9 0x000055e2da245961 mlir::AffineLoadOp::fold(llvm::ArrayRef) (.part.0) AffineOps.cpp:0:0 #10 0x000055e2da2461e5 _ZN4llvm6detail18UniqueFunctionBaseIN4mlir13LogicalResultEJPNS2_9OperationENS_8ArrayRefINS2_9AttributeEEERNS_15SmallVectorImplINS2_12OpFoldResultEEEEE8CallImplIKZNS2_2OpINS2_12AffineLoadOpEJNS2_7OpTrait11ZeroRegionsENSH_9OneResultENSH_14OneTypedResultINS2_4TypeEE4ImplENSH_14ZeroSuccessorsENSH_16AtLeastNOperandsILj1EE4ImplENSH_12OpInvariantsENS2_21AffineReadOpInterface5TraitENS2_24AffineMapAccessInterface5TraitENSH_19MemRefsNormalizableENS2_23MemoryEffectOpInterface5TraitEEE17getFoldHookFnImplISG_EENSt9enable_ifIXaasrSt11disjunctionIJSt7is_sameINSJ_IT_EENSI_IS15_EEES14_IS16_S16_ES14_IS16_NSM_4ImplIS15_EEES14_IS16_NSO_IS15_EEES14_IS16_NSQ_4ImplIS15_EEES14_IS16_NSS_IS15_EEES14_IS16_NST_5TraitIS15_EEES14_IS16_NSV_5TraitIS15_EEES14_IS16_NSX_IS15_EEES14_IS16_NSY_5TraitIS15_EEEEE5valuesrNS0_8detectorIvNS10_22has_single_result_foldEJS15_EE7value_tE5valueENS_15unique_functionIKFS3_S5_S8_SC_EEEE4typeEvEUlS5_S8_SC_E_EES3_PvS5_S8_SC_ (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x1501e5) #11 0x000055e2db974a02 mlir::Operation::fold(llvm::ArrayRef, llvm::SmallVectorImpl&) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x187ea02) #12 0x000055e2db8bb2cb mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl&) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x17c52cb) #13 0x000055e2db68d63b (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0 #14 0x000055e2db69057a (anonymous namespace)::OperationLegalizer::legalizePatternResult(mlir::Operation*, mlir::Pattern const&, mlir::ConversionPatternRewriter&, (anonymous namespace)::RewriterState&) (.isra.0) DialectConversion.cpp:0:0 #15 0x000055e2db6909c7 mlir::LogicalResult llvm::function_ref::callback_fn<(anonymous namespace)::OperationLegalizer::legalizeWithPattern(mlir::Operation*, mlir::ConversionPatternRewriter&)::'lambda1'(mlir::Pattern const&)>(long, mlir::Pattern const&) DialectConversion.cpp:0:0 #16 0x000055e2db6bedae mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref, llvm::function_ref, llvm::function_ref) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x15c8dae) #17 0x000055e2db68d78e (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0 #18 0x000055e2db68df6e (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef, llvm::function_ref) DialectConversion.cpp:0:0 #19 0x000055e2db68fe00 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget&, mlir::FrozenRewritePatternSet const&, llvm::DenseSet>*) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x1599e00) #20 0x000055e2dab1950b (anonymous namespace)::ConvertPolygeistToLLVMPass::convertModule(mlir::ModuleOp, bool) /home/jabcross/repos/Polygeist/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp:2953:17 #21 0x000055e2dab19ccd (anonymous namespace)::ConvertPolygeistToLLVMPass::runOnOperation() /home/jabcross/repos/Polygeist/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp:3001:3 #22 0x000055e2db7a1e99 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x16abe99) #23 0x000055e2db7a2581 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x16ac581) #24 0x000055e2db7a2db4 mlir::PassManager::run(mlir::Operation*) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x16acdb4) #25 0x000055e2dacdc04b performActions(llvm::raw_ostream&, bool, bool, llvm::SourceMgr&, mlir::MLIRContext*, llvm::function_ref, bool, bool) (.isra.0) MlirOptMain.cpp:0:0 #26 0x000055e2dacdca43 processBuffer(llvm::raw_ostream&, std::unique_ptr>, bool, bool, bool, bool, bool, bool, llvm::function_ref, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0 #27 0x000055e2dacdcc53 mlir::LogicalResult llvm::function_ref>, llvm::raw_ostream&)>::callback_fn>, llvm::function_ref, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool)::'lambda'(std::unique_ptr>, llvm::raw_ostream&)>(long, std::unique_ptr>, llvm::raw_ostream&) MlirOptMain.cpp:0:0 #28 0x000055e2db9cb8b3 mlir::splitAndProcessBuffer(std::unique_ptr>, llvm::function_ref>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x18d58b3) #29 0x000055e2dacdafec mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr>, mlir::PassPipelineCLParser const&, mlir::DialectRegistry&, bool, bool, bool, bool, bool, bool, bool, bool) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0xbe4fec) #30 0x000055e2dacdd1fc mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&, bool) (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0xbe71fc) #31 0x000055e2da20233f main /home/jabcross/repos/Polygeist/tools/polygeist-opt/polygeist-opt.cpp:108:22 #32 0x00007f8236e27cd0 (/usr/lib/libc.so.6+0x27cd0) #33 0x00007f8236e27d8a __libc_start_main (/usr/lib/libc.so.6+0x27d8a) #34 0x000055e2da201d65 _start (/home/jabcross/repos/Polygeist/build/bin/polygeist-opt+0x10bd65) [1] 324054 IOT instruction (core dumped) $POLYGEIST_OPT --convert-polygeist-to-llvm test.mlir```
ivanradanov commented 1 year ago

--convert-polygest-to-llvm expects the affine dialect to be already lowered.

Try running --lower-affine before that.