Skip to content

[Mlir] --int-range-optimizations crashes in StorageUniquerSupport.h:180 #122076

Open
@anonymoususer-1

Description

@anonymoususer-1

git version: e4372c4

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt a.mlir --int-range-optimizations

a.mlir:

module {
  llvm.mlir.global private constant @assert_msg_23(dense<"0x4552524F523A2052756E74696D65206F7020766572696669636174696F6E206661696C65640A226C696E616C672E67656E657269632228253234372C202536342C202538342C202533323529203C7B696E646578696E675F6D617073203D205B616666696E655F6D61703C2864302C20643129202D3E202864302C206431293E2C20616666696E655F6D61703C2864302C20643129202D3E202864302C206431293E2C20616666696E655F6D61703C2864302C20643129202D3E202864302C206431293E2C20616666696E655F6D61703C2864302C20643129202D3E202864302C206431293E5D2C206974657261746F725F7479706573203D205B236C696E616C672E6974657261746F725F747970653C706172616C6C656C3E2C20236C696E616C672E6974657261746F725F747970653C706172616C6C656C3E5D2C206F706572616E645365676D656E7453697A6573203D2061727261793C6933323A20332C20313E7D3E20287B2E2E2E7D29203A20286D656D7265663C32347832397869313E2C206D656D7265663C3234783239786933323E2C206D656D7265663C3234783239786933323E2C206D656D7265663C3234783239786933323E29202D3E2028290A5E20756E6578706563746564206E6567617469766520726573756C74206F6E2064696D656E73696F6E202330206F6620696E7075742F6F7574707574206F706572616E642023310A4C6F636174696F6E3A206C6F6328222F646174612F737A792F776F726B73706163652F6D6C69722D696E636F6E73697374656E742F73616D706C655F746D702F746F73612E2E363137646638616565663139373631312E6D6C69722F746F73612E2E363137646638616565663139373631312E6D6C69722E2E363335373532326566633662623465632E6D6C6972223A3434333A352900"> : tensor<674xi8>) {addr_space = 0 : i32} : !llvm.array<674 x i8>
  llvm.func @abort()
  llvm.func @puts(!llvm.ptr)
 llvm.mlir.global private constant @assert_msg(dense<"0x4552524F523A2052756E74696D65206F7020766572696669636174696F6E206661696C65640A226C696E616C672E67656E6572696322282539342C202531383329203C7B696E646578696E675F6D617073203D205B616666696E655F6D61703C2864302C20643129202D3E202864302C206431293E2C20616666696E655F6D61703C2864302C20643129202D3E202864302C206431293E5D2C206974657261746F725F7479706573203D205B236C696E616C672E6974657261746F725F747970653C706172616C6C656C3E2C20236C696E616C672E6974657261746F725F747970653C706172616C6C656C3E5D2C206F706572616E645365676D656E7453697A6573203D2061727261793C6933323A20312C20313E7D3E20287B2E2E2E7D29203A20286D656D7265663C3234783239786933323E2C206D656D7265663C3234783239786933323E29202D3E2028290A5E20756E6578706563746564206E6567617469766520726573756C74206F6E2064696D656E73696F6E202330206F6620696E7075742F6F7574707574206F706572616E642023300A4C6F636174696F6E3A206C6F6328222F646174612F737A792F776F726B73706163652F6D6C69722D696E636F6E73697374656E742F73616D706C655F746D702F746F73612E2E363137646638616565663139373631312E6D6C69722F746F73612E2E363137646638616565663139373631312E6D6C69722E2E363335373532326566633662623465632E6D6C6972223A3337333A352900"> : tensor<558xi8>) {addr_space = 0 : i32} : !llvm.array<558 x i8>
  llvm.func @malloc(i64) -> !llvm.ptr
  func.func @func2(%arg0: memref<1x24x29xi32, strided<[?, ?, ?], offset: ?>>, %arg1: memref<1x24x29xi32, strided<[?, ?, ?], offset: ?>>, %arg2: memref<1x24x29xi32, strided<[?, ?, ?], offset: ?>>) -> memref<1x24x29xi32> {
    %c29 = arith.constant 29 : index
    %c1 = arith.constant 1 : index
    %c24 = arith.constant 24 : index
    %c0 = arith.constant 0 : index
    %0 = llvm.mlir.constant(true) : i1
    %1 = llvm.mlir.constant(64 : index) : i64
    %6 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)>
    %14 = llvm.mlir.constant(0 : index) : i64
    %20 = llvm.mlir.constant(24 : index) : i64
    %21 = llvm.mlir.constant(29 : index) : i64
    %22 = llvm.mlir.constant(1 : index) : i64
    %23 = llvm.mlir.constant(696 : index) : i64
    %24 = llvm.mlir.zero : !llvm.ptr
    %96 = llvm.getelementptr %24[696] : (!llvm.ptr) -> !llvm.ptr, i32
    %97 = llvm.ptrtoint %96 : !llvm.ptr to i64
    %98 = llvm.add %97, %1 : i64
    %99 = llvm.call @malloc(%98) : (i64) -> !llvm.ptr
    %100 = llvm.ptrtoint %99 : !llvm.ptr to i64
    %101 = llvm.sub %1, %22 : i64
    %102 = llvm.add %100, %101 : i64
    %103 = llvm.urem %102, %1 : i64
    %104 = llvm.sub %102, %103 : i64
    %105 = llvm.inttoptr %104 : i64 to !llvm.ptr
    %106 = llvm.insertvalue %99, %6[0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %107 = llvm.insertvalue %105, %106[1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %108 = llvm.insertvalue %14, %107[2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %109 = llvm.insertvalue %22, %108[3, 0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %110 = llvm.insertvalue %20, %109[3, 1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %111 = llvm.insertvalue %21, %110[3, 2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %112 = llvm.insertvalue %23, %111[4, 0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %113 = llvm.insertvalue %21, %112[4, 1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %114 = llvm.insertvalue %22, %113[4, 2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %119 = builtin.unrealized_conversion_cast %114 : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> to memref<1x24x29xi32>
    %collapse_shape = memref.collapse_shape %119 [[0, 1], [2]] : memref<1x24x29xi32> into memref<24x29xi32>
    %120 = builtin.unrealized_conversion_cast %collapse_shape : memref<24x29xi32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
    llvm.cond_br %0, ^bb72, ^bb81
   ^bb72:  // pred: ^bb71
    %collapse_shape_3 = memref.collapse_shape %119 [[0, 1], [2]] : memref<1x24x29xi32> into memref<24x29xi32>
    %211 = builtin.unrealized_conversion_cast %collapse_shape_3 : memref<24x29xi32> to !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
    llvm.cond_br %0, ^bb80, ^bb105
  ^bb80:  // pred: ^bb79
    %213 = scf.while (%arg3 = %c0) : (index) -> index {
      %374 = arith.cmpi slt, %arg3, %c24 : index
      scf.condition(%374) %arg3 : index
    } do {
    ^bb0(%arg3: index):
      %374 = arith.addi %arg3, %c1 : index
      %375 = builtin.unrealized_conversion_cast %arg3 : index to i64
      %376 = scf.while (%arg4 = %c0) : (index) -> index {
        %true = arith.constant true
        scf.condition(%true) %arg4 : index
      } do {
      ^bb0(%arg4: index):
        scf.yield %arg4 : index
      }
      %377 = scf.while (%arg4 = %c0) : (index) -> index {
        %378 = arith.cmpi slt, %arg4, %c29 : index
        scf.condition(%378) %arg4 : index
      } do {
      ^bb0(%arg4: index):
        %378 = arith.addi %arg4, %c1 : index
        %379 = builtin.unrealized_conversion_cast %arg4 : index to i64
        %380 = llvm.mul %375, %21 : i64
        %381 = llvm.add %380, %379 : i64
        %382 = llvm.getelementptr %105[%381] : (!llvm.ptr, i64) -> !llvm.ptr, f32
        %383 = llvm.load %382 : !llvm.ptr -> f32
        %384 = llvm.intr.exp(%383) : (f32) -> f32
        %385 = llvm.extractvalue %211[1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
        %386 = llvm.mul %375, %21 : i64
        %387 = llvm.add %386, %379 : i64
        %388 = llvm.getelementptr %385[%387] : (!llvm.ptr, i64) -> !llvm.ptr, f32
        llvm.store %384, %388 : f32, !llvm.ptr
        scf.yield %378 : index
      }
      scf.yield %374 : index
    }
    return %119 : memref<1x24x29xi32>
  ^bb81:  // pred: ^bb0
    %214 = llvm.mlir.addressof @assert_msg : !llvm.ptr
    %215 = llvm.getelementptr %214[0] : (!llvm.ptr) -> !llvm.ptr, !llvm.array<558 x i8>
    llvm.call @puts(%215) : (!llvm.ptr) -> ()
    llvm.call @abort() : () -> ()
  llvm.unreachable
  ^bb105:  // pred: ^bb24
    %262 = llvm.mlir.addressof @assert_msg_23 : !llvm.ptr
    %263 = llvm.getelementptr %262[0] : (!llvm.ptr) -> !llvm.ptr, !llvm.array<674 x i8>
    llvm.call @puts(%263) : (!llvm.ptr) -> ()
    llvm.call @abort() : () -> ()
    llvm.unreachable
  }
}

stack trace:

mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/include/mlir/IR/StorageUniquerSupport.h:180: static ConcreteT mlir::detail::StorageUserBase<mlir::IntegerAttr, mlir::Attribute, mlir::detail::IntegerAttrStorage, mlir::detail::AttributeUniquer, mlir::TypedAttr::Trait>::get(MLIRContext *, Args &&...) [ConcreteT = mlir::IntegerAttr, BaseT = mlir::Attribute, StorageT = mlir::detail::IntegerAttrStorage, UniquerT = mlir::detail::AttributeUniquer, Traits = <mlir::TypedAttr::Trait>, Args = <mlir::Type &, const llvm::APInt &>]: Assertion `succeeded( ConcreteT::verifyInvariants(getDefaultDiagnosticEmitFn(ctx), args...))' 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/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir --int-range-optimizations
 #0 0x00005617973d5ce8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11f2ce8)
 #1 0x00005617973d37fe llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11f07fe)
 #2 0x00005617973d667d SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f078bb4c420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f078b18900b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007f078b168859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007f078b168729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007f078b168729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007f078b179fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x000056179a414001 (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4231001)
#10 0x000056179a413e7f mlir::IntegerAttr::get(mlir::Type, llvm::APInt const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4230e7f)
#11 0x0000561797700de7 maybeReplaceWithConstant(mlir::DataFlowSolver&, mlir::PatternRewriter&, mlir::Value) IntRangeOptimizations.cpp:0:0
#12 0x00005617976ff850 (anonymous namespace)::MaterializeKnownConstantValues::rewrite(mlir::Operation*, mlir::PatternRewriter&) const IntRangeOptimizations.cpp:0:0
#13 0x0000561797700bc7 mlir::RewritePattern::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&) const (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x151dbc7)
#14 0x000056179d44fd31 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<llvm::LogicalResult (mlir::Pattern const&)>)::$_0>(long) PatternApplicator.cpp:0:0
#15 0x000056179d44ca51 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<llvm::LogicalResult (mlir::Pattern const&)>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x7269a51)
#16 0x000056179a3a8feb (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#17 0x000056179a3a59af mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41c29af)
#18 0x0000561797705058 (anonymous namespace)::IntRangeOptimizationsPass::runOnOperation() IntRangeOptimizations.cpp:0:0
#19 0x000056179a330496 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414d496)
#20 0x000056179a330dc0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x414ddc0)
#21 0x000056179a3336c2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41506c2)
#22 0x000056179a32baea performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x000056179a32b73d 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&) MlirOptMain.cpp:0:0
#24 0x000056179a3d2785 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-release/llvm-project/build/bin/mlir-opt+0x41ef785)
#25 0x000056179a325755 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4142755)
#26 0x000056179a3259ff mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x41429ff)
#27 0x000056179a325d2e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4142d2e)
#28 0x00005617973b4a67 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11d1a67)
#29 0x00007f078b16a083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#30 0x00005617973b45de _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11d15de)

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions