Skip to content

[Mlir] --normalize-memrefs crashes in StorageUniquerSupport.h:113 #122090

@Emilyaxe

Description

@Emilyaxe

git version: e4372c4

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt a.mlir --normalize-memrefs

a.mlir:

module {
  llvm.func @malloc(i64) -> !llvm.ptr attributes {sym_visibility = "private"}
   func.func private @entry(%arg0: index) -> () {
    %c140 = arith.constant 140 : index
    %c15 = arith.constant 15 : index
    %c1 = arith.constant 1 : index
    %c3 = arith.constant 3 : index
    %c0 = arith.constant 0 : index
    %1 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)>
    %2 = llvm.mlir.constant(64 : index) : i64
    %3 = llvm.mlir.constant(2100 : index) : i64
    %4 = llvm.mlir.constant(140 : index) : i64
    %5 = llvm.mlir.constant(3 : index) : i64
    %6 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
    %14 = llvm.mlir.constant(0 : index) : i64
    %15 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)>
    %16 = llvm.mlir.constant(3735928559 : index) : i64
    %18 = llvm.mlir.zero : !llvm.ptr
    %19 = llvm.mlir.constant(420 : index) : i64
    %20 = llvm.mlir.constant(28 : index) : i64
    %21 = llvm.mlir.constant(15 : index) : i64
    %22 = llvm.mlir.constant(1 : index) : i64
    %27 = llvm.mlir.constant(-3.40282347E+38 : f32) : f32
    %105 = llvm.getelementptr %18[6300] : (!llvm.ptr) -> !llvm.ptr, f32
    %106 = llvm.ptrtoint %105 : !llvm.ptr to i64
    %107 = llvm.add %106, %2 : i64
    %110 = llvm.sub %2, %22 : i64
    %125 = llvm.call @malloc(%107) : (i64) -> !llvm.ptr
    %126 = llvm.ptrtoint %125 : !llvm.ptr to i64
    %127 = llvm.add %126, %110 : i64
    %128 = llvm.urem %127, %2 : i64
    %129 = llvm.sub %127, %128 : i64
    %130 = llvm.inttoptr %129 : i64 to !llvm.ptr
    llvm.br ^bb18
  ^bb18:  // pred: ^bb8
    %208 = llvm.getelementptr %18[420] : (!llvm.ptr) -> !llvm.ptr, f32
    %209 = llvm.ptrtoint %208 : !llvm.ptr to i64
    %210 = llvm.add %209, %2 : i64
    %211 = llvm.call @malloc(%210) : (i64) -> !llvm.ptr
    %212 = llvm.ptrtoint %211 : !llvm.ptr to i64
    %213 = llvm.add %212, %110 : i64
    %214 = llvm.urem %213, %2 : i64
    %215 = llvm.sub %213, %214 : i64
    %216 = llvm.inttoptr %215 : i64 to !llvm.ptr
    %217 = llvm.insertvalue %211, %15[0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %218 = llvm.insertvalue %216, %217[1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %219 = llvm.insertvalue %14, %218[2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %220 = llvm.insertvalue %5, %219[3, 0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %221 = llvm.insertvalue %22, %220[3, 1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %222 = llvm.insertvalue %4, %221[3, 2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %223 = llvm.insertvalue %4, %222[4, 0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %224 = llvm.insertvalue %4, %223[4, 1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %225 = llvm.insertvalue %22, %224[4, 2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %226 = builtin.unrealized_conversion_cast %225 : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> to memref<3x1x140xf32>
    %base_buffer, %offset, %sizes:3, %strides:3 = memref.extract_strided_metadata %226 : memref<3x1x140xf32> -> memref<f32>, index, index, index, index, index, index, index
    %reinterpret_cast = memref.reinterpret_cast %base_buffer to offset: [0], sizes: [3, 140], strides: [140, 1] : memref<f32> to memref<3x140xf32, strided<[140, 1]>>
    memref.store %27, %reinterpret_cast[%c0, %c0] : memref<3x140xf32, strided<[140, 1]>>
    llvm.br ^bb26
  ^bb26:  // pred: ^bb21
    %242 = llvm.insertvalue %125, %1[0] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %243 = llvm.insertvalue %130, %242[1] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %244 = llvm.insertvalue %14, %243[2] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %245 = llvm.insertvalue %5, %244[3, 0] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %246 = llvm.insertvalue %3, %245[4, 0] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %247 = llvm.insertvalue %21, %246[3, 1] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %248 = llvm.insertvalue %4, %247[4, 1] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %249 = llvm.insertvalue %22, %248[3, 2] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %250 = llvm.insertvalue %4, %249[4, 2] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %251 = llvm.insertvalue %4, %250[3, 3] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %252 = llvm.insertvalue %22, %251[4, 3] : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> 
    %253 = builtin.unrealized_conversion_cast %252 : !llvm.struct<(ptr, ptr, i64, array<4 x i64>, array<4 x i64>)> to memref<3x15x1x140xf32>
    %base_buffer_0, %offset_1, %sizes_2:4, %strides_3:4 = memref.extract_strided_metadata %253 : memref<3x15x1x140xf32> -> memref<f32>, index, index, index, index, index, index, index, index, index
    %reinterpret_cast_4 = memref.reinterpret_cast %base_buffer_0 to offset: [0], sizes: [3, 15, 140], strides: [2100, 140, 1] : memref<f32> to memref<3x15x140xf32, strided<[2100, 140, 1]>>
    %254 = memref.load %reinterpret_cast_4[%c0, %c0, %c0] : memref<3x15x140xf32, strided<[2100, 140, 1]>>
    %255 = memref.load %reinterpret_cast[%c0, %c0] : memref<3x140xf32, strided<[140, 1]>>
    %256 = llvm.fcmp "ugt" %254, %255 : f32
    %257 = llvm.select %256, %254, %255 : i1, f32
    %258 = llvm.fcmp "uno" %255, %255 : f32
    %259 = llvm.select %258, %255, %257 : i1, f32
    memref.store %259, %reinterpret_cast[%c0, %c0] : memref<3x140xf32, strided<[140, 1]>>
    return
  }
}

stack trace:


PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/szy/MLIR/llvm-debug/llvm-project/build/bin/mlir-opt a.mlir --normalize-memrefs
 #0 0x0000556d49eec799 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /data/szy/MLIR/llvm-debug/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:11
 #1 0x0000556d49eecc4b PrintStackTraceSignalHandler(void*) /data/szy/MLIR/llvm-debug/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x0000556d49eeae7f llvm::sys::RunSignalHandlers() /data/szy/MLIR/llvm-debug/llvm-project/llvm/lib/Support/Signals.cpp:105:5
 #3 0x0000556d49eed31e SignalHandler(int) /data/szy/MLIR/llvm-debug/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f76247d8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #5 0x0000556d4a04869c mlir::AbstractType::getTypeID() const /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/TypeSupport.h:107:37
 #6 0x0000556d4a048600 mlir::Type::getTypeID() /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/Types.h:117:55
 #7 0x0000556d4a068b15 bool mlir::detail::StorageUserBase<mlir::MemRefType, mlir::BaseMemRefType, mlir::detail::MemRefTypeStorage, mlir::detail::TypeUniquer, mlir::ShapedType::Trait>::classof<mlir::Type>(mlir::Type) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/StorageUniquerSupport.h:113:16
 #8 0x0000556d4a0b72fd llvm::CastInfo<mlir::MemRefType, mlir::Type, void>::isPossible(mlir::Type) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/Types.h:423:7
 #9 0x0000556d4a0b72ad llvm::DefaultDoCastIfPossible<mlir::MemRefType, mlir::Type, llvm::CastInfo<mlir::MemRefType, mlir::Type, void>>::doCastIfPossible(mlir::Type) /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/Support/Casting.h:311:9
#10 0x0000556d4a0b7278 decltype(auto) llvm::dyn_cast<mlir::MemRefType, mlir::Type>(mlir::Type&) /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/Support/Casting.h:657:10
#11 0x0000556d4c88a443 (anonymous namespace)::NormalizeMemRefs::createOpResultsNormalized(mlir::func::FuncOp, mlir::Operation*) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Dialect/MemRef/Transforms/NormalizeMemRefs.cpp:508:29
#12 0x0000556d4c889fea (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2::operator()(mlir::Operation*) const /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Dialect/MemRef/Transforms/NormalizeMemRefs.cpp:414:18
#13 0x0000556d4c889f3d void llvm::function_ref<void (mlir::Operation*)>::callback_fn<(anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2>(long, mlir::Operation*) /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#14 0x0000556d4a0ed8f1 llvm::function_ref<void (mlir::Operation*)>::operator()(mlir::Operation*) const /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#15 0x0000556d4a0ed8bd void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/Visitors.h:187:1
#16 0x0000556d4a0ed879 void mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<void (mlir::Operation*)>, mlir::WalkOrder) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/Visitors.h:179:27
#17 0x0000556d4c889ee2 std::enable_if<llvm::is_one_of<mlir::Operation*, mlir::Operation*, mlir::Region*, mlir::Block*>::value, void>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2, mlir::Operation*, void>(mlir::Operation*, (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2&&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/Visitors.h:312:3
#18 0x0000556d4c889e8d std::enable_if<llvm::function_traits<std::decay<(anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2>::type>::num_args == 1, void>::type mlir::Operation::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2, void>((anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2&&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/Operation.h:794:5
#19 0x0000556d4c888dc0 std::enable_if<llvm::function_traits<std::decay<(anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2>::type>::num_args == 1, void>::type mlir::OpState::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2, void>((anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp)::$_2&&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/OpDefinition.h:166:5
#20 0x0000556d4c88780e (anonymous namespace)::NormalizeMemRefs::normalizeFuncOpMemRefs(mlir::func::FuncOp, mlir::ModuleOp) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Dialect/MemRef/Transforms/NormalizeMemRefs.cpp:463:14
#21 0x0000556d4c8871d8 (anonymous namespace)::NormalizeMemRefs::runOnOperation() /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Dialect/MemRef/Transforms/NormalizeMemRefs.cpp:97:29
#22 0x0000556d4f7e43f4 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1::operator()() const /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Pass/Pass.cpp:0:17
#23 0x0000556d4f7e4395 void llvm::function_ref<void ()>::callback_fn<mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int)::$_1>(long) /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
#24 0x0000556d49f10859 llvm::function_ref<void ()>::operator()() const /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
#25 0x0000556d4f7e713b void mlir::MLIRContext::executeAction<mlir::PassExecutionAction, mlir::Pass&>(llvm::function_ref<void ()>, llvm::ArrayRef<mlir::IRUnit>, mlir::Pass&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/include/mlir/IR/MLIRContext.h:281:3
#26 0x0000556d4f7dff97 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Pass/Pass.cpp:532:17
#27 0x0000556d4f7e04b7 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Pass/Pass.cpp:592:16
#28 0x0000556d4f7e1e08 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Pass/Pass.cpp:905:10
#29 0x0000556d4f7e1d43 mlir::PassManager::run(mlir::Operation*) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Pass/Pass.cpp:885:60
#30 0x0000556d4f7d3f95 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:474:17
#31 0x0000556d4f7d3b86 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPoolInterface*) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:542:12
#32 0x0000556d4f7d394c mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0::operator()(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) const /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:625:12
#33 0x0000556d4f7d38e6 llvm::LogicalResult llvm::function_ref<llvm::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&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#34 0x0000556d4f9504f2 llvm::function_ref<llvm::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 /data/szy/MLIR/llvm-debug/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:12
#35 0x0000556d4f94fb05 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Support/ToolUtilities.cpp:27:12
#36 0x0000556d4f7d0413 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:628:10
#37 0x0000556d4f7d07b5 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:669:14
#38 0x0000556d4f7d0988 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) /data/szy/MLIR/llvm-debug/llvm-project/mlir/lib/Tools/mlir-opt/MlirOptMain.cpp:685:10
#39 0x0000556d49e75de3 main /data/szy/MLIR/llvm-debug/llvm-project/mlir/tools/mlir-opt/mlir-opt.cpp:323:33
#40 0x00007f7623df6083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#41 0x0000556d49e759fe _start (/data/szy/MLIR/llvm-debug/llvm-project/build/bin/mlir-opt+0x26519fe)

Metadata

Metadata

Assignees

No one assigned

    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