Skip to content

[mlir] --test-scf-if-utils crashes #119378

@Emilyaxe

Description

@Emilyaxe

git version: 953838d

system: Ubuntu 18.04.6 LTS

reproduce with: mlir-opt --test-scf-if-utils a.mlir

a.mlir:

#map = affine_map<(d0, d1) -> (d0 + d1)>
module {
  llvm.func @malloc(i64) -> !llvm.ptr
  llvm.func @func1(%arg0: !llvm.ptr, %arg1: !llvm.ptr, %arg2: i64, %arg3: i64, %arg4: i64, %arg5: i64, %arg6: i64, %arg7: i64, %arg8: i64) -> !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> {
    %c19 = arith.constant 19 : index
    %c1 = arith.constant 1 : index
    %c32 = arith.constant 32 : index
    %c0 = arith.constant 0 : index
    %0 = llvm.mlir.constant(dense<1.000000e+00> : vector<32x256xf32>) : !llvm.array<32 x vector<256xf32>>
    %1 = llvm.mlir.zero : !llvm.ptr
    %2 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
    %3 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)>
    %4 = llvm.mlir.constant(0 : index) : i64
    %5 = llvm.mlir.constant(19 : index) : i64
    %6 = llvm.mlir.constant(32 : index) : i64
    %7 = llvm.mlir.constant(4 : index) : i64
    %8 = llvm.mlir.constant(256 : index) : i64
    %9 = llvm.mlir.constant(64 : index) : i64
    %10 = llvm.mlir.constant(1 : index) : i64
    %11 = llvm.mlir.constant(76 : index) : i64
    %alloca = memref.alloca() : memref<vector<32x256xf32>>
    %12 = builtin.unrealized_conversion_cast %0 : !llvm.array<32 x vector<256xf32>> to vector<32x256xf32>
    %13 = llvm.getelementptr %1[76] : (!llvm.ptr) -> !llvm.ptr, f32
    %14 = llvm.ptrtoint %13 : !llvm.ptr to i64
    %15 = llvm.add %14, %9 : i64
    %16 = llvm.call @malloc(%15) : (i64) -> !llvm.ptr
    %17 = llvm.ptrtoint %16 : !llvm.ptr to i64
    %18 = llvm.sub %9, %10 : i64
    %19 = llvm.add %17, %18 : i64
    %20 = llvm.urem %19, %9 : i64
    %21 = llvm.sub %19, %20 : i64
    %22 = llvm.inttoptr %21 : i64 to !llvm.ptr
    %23 = llvm.insertvalue %16, %3[0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %24 = llvm.insertvalue %22, %23[1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %25 = llvm.insertvalue %4, %24[2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %26 = llvm.insertvalue %10, %25[3, 0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %27 = llvm.insertvalue %5, %26[3, 1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %28 = llvm.insertvalue %7, %27[3, 2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %29 = llvm.insertvalue %11, %28[4, 0] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %30 = llvm.insertvalue %7, %29[4, 1] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %31 = llvm.insertvalue %10, %30[4, 2] : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)> 
    %32 = llvm.insertvalue %16, %2[0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %33 = llvm.insertvalue %22, %32[1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %34 = llvm.insertvalue %4, %33[2] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %35 = llvm.insertvalue %5, %34[3, 0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %36 = llvm.insertvalue %7, %35[4, 0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %37 = llvm.insertvalue %7, %36[3, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %38 = llvm.insertvalue %10, %37[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> 
    %39 = builtin.unrealized_conversion_cast %38 : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)> to memref<19x4xf32>
    llvm.br ^bb1(%4 : i64)
  ^bb1(%40: i64):  // 2 preds: ^bb0, ^bb5
    %41 = builtin.unrealized_conversion_cast %40 : i64 to index
    %42 = llvm.icmp "slt" %40, %5 : i64
    llvm.cond_br %42, ^bb2, ^bb6
  ^bb2:  // pred: ^bb1
    llvm.br ^bb3(%4 : i64)
  ^bb3(%43: i64):  // 2 preds: ^bb2, ^bb4
    %44 = builtin.unrealized_conversion_cast %43 : i64 to index
    %45 = llvm.icmp "slt" %43, %7 : i64
    llvm.cond_br %45, ^bb4, ^bb5
  ^bb4:  // pred: ^bb3
    memref.store %12, %alloca[] : memref<vector<32x256xf32>>
    %46 = vector.type_cast %alloca : memref<vector<32x256xf32>> to memref<32xvector<256xf32>>
    scf.for %arg9 = %c0 to %c32 step %c1 {
      %49 = affine.apply #map(%41, %arg9)
      %50 = arith.cmpi slt, %49, %c19 : index
      scf.if %50 {
        %51 = affine.apply #map(%41, %arg9)
        %52 = memref.load %46[%arg9] : memref<32xvector<256xf32>>
        vector.transfer_write %52, %39[%51, %44] : vector<256xf32>, memref<19x4xf32>
      } else {
      }
    }
    %47 = llvm.add %43, %8 : i64
    llvm.br ^bb3(%47 : i64)
  ^bb5:  // pred: ^bb3
    %48 = llvm.add %40, %6 : i64
    llvm.br ^bb1(%48 : i64)
  ^bb6:  // pred: ^bb1
    llvm.return %31 : !llvm.struct<(ptr, ptr, i64, array<3 x i64>, array<3 x i64>)>
  }

}


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-release/llvm-project/build/bin/mlir-opt a.mlir --test-scf-if-utils
 #0 0x00005628ab8f1158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1136158)
 #1 0x00005628ab8eec6e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1133c6e)
 #2 0x00005628ab8f1aed SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f4058d10420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00005628ad74d0c7 mlir::outlineSingleBlockRegion(mlir::RewriterBase&, mlir::Location, mlir::Region&, llvm::StringRef, mlir::func::CallOp*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2f920c7)
 #5 0x00005628ad74e055 mlir::outlineIfOp(mlir::RewriterBase&, mlir::scf::IfOp, mlir::func::FuncOp*, llvm::StringRef, mlir::func::FuncOp*, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x2f93055)
 #6 0x00005628ae7cc6c5 mlir::WalkResult llvm::function_ref<mlir::WalkResult (mlir::Operation*)>::callback_fn<std::enable_if<!llvm::is_one_of<mlir::scf::IfOp, mlir::Operation*, mlir::Region*, mlir::Block*>::value && std::is_same<mlir::WalkResult, mlir::WalkResult>::value, mlir::WalkResult>::type mlir::detail::walk<(mlir::WalkOrder)1, mlir::ForwardIterator, (anonymous namespace)::TestSCFIfUtilsPass::runOnOperation()::'lambda'(mlir::scf::IfOp), mlir::scf::IfOp, mlir::WalkResult>(mlir::Operation*, (anonymous namespace)::TestSCFIfUtilsPass::runOnOperation()::'lambda'(mlir::scf::IfOp)&&)::'lambda'(mlir::Operation*)>(long, mlir::Operation*) TestSCFUtils.cpp:0:0
 #7 0x00005628aba1ce77 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1261e77)
 #8 0x00005628aba1ce77 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1261e77)
 #9 0x00005628aba1ce77 mlir::WalkResult mlir::detail::walk<mlir::ForwardIterator>(mlir::Operation*, llvm::function_ref<mlir::WalkResult (mlir::Operation*)>, mlir::WalkOrder) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1261e77)
#10 0x00005628ae7cc1e7 (anonymous namespace)::TestSCFIfUtilsPass::runOnOperation() TestSCFUtils.cpp:0:0
#11 0x00005628aed322b6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45772b6)
#12 0x00005628aed32be0 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+0x4577be0)
#13 0x00005628aed351b2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x457a1b2)
#14 0x00005628aed2da5a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#15 0x00005628aed2d6ad 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
#16 0x00005628aedd9b25 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+0x461eb25)
#17 0x00005628aed27695 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+0x456c695)
#18 0x00005628aed2793f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456c93f)
#19 0x00005628aed27c6e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456cc6e)
#20 0x00005628ab8d1c47 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1116c47)
#21 0x00007f405832e083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#22 0x00005628ab8d17be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11167be)

Metadata

Metadata

Assignees

Labels

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

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions