llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir] `--duplicate-function-elimination` crashes when replacing symbol uses across nested symbol tables

Open frida-albrecht opened this issue 1 month ago • 3 comments

The --duplicate-function-elimination pass crashes with an assertion failure when processing duplicate functions defined in different symbol scopes, including a nested gpu.module.

test commit: 7a941df

test case:

#map = affine_map<(d0, d1, d2) -> (d0, d1 - d2)>
module attributes {gpu.container_module} {
  llvm.func @malloc(i64) -> !llvm.ptr
  gpu.module @main_kernel_0 {
    func.func private @parallel_compute_fn_0(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: index, %arg8: index, %arg9: i64, %arg10: !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, %arg11: i64, %arg12: !llvm.ptr) {
      %cst = arith.constant 6.000000e-01 : f32
      %c64 = arith.constant 64 : index
      %cst_0 = arith.constant 8.000000e-01 : f32
      %c32 = arith.constant 32 : index
      %cst_1 = arith.constant 1.000000e+00 : f32
      %c16 = arith.constant 16 : index
      %cst_2 = arith.constant 2.000000e+00 : f32
      %c8 = arith.constant 8 : index
      %cst_3 = arith.constant 4.000000e+00 : f32
      %c4 = arith.constant 4 : index
      %cst_4 = arith.constant 8.000000e+00 : f32
      %c1000 = arith.constant 1000 : index
      %c0 = arith.constant 0 : index
      %c1 = arith.constant 1 : index
      %0 = arith.muli %arg0, %arg1 : index
      %1 = arith.addi %0, %arg1 : index
      %2 = arith.minsi %1, %arg2 : index
      %3 = arith.subi %2, %c1 : index
      %4 = arith.remsi %0, %arg2 : index
      %5 = arith.remsi %3, %arg2 : index
      %6 = arith.addi %5, %c1 : index
      scf.for %arg13 = %4 to %6 step %c1 {
        %7 = arith.muli %arg13, %arg5 : index
        %8 = arith.addi %arg3, %7 : index
        %9 = affine.min #map(%arg6, %arg7, %8)
        %10 = arith.ceildivsi %9, %arg8 : index
        %11 = arith.cmpi eq, %10, %c0 : index
        scf.if %11 {
        } else {
          %12 = async.runtime.num_worker_threads : index
          %13 = arith.cmpi sgt, %12, %c4 : index
          %14 = arith.select %13, %cst_3, %cst_4 : f32
          %15 = arith.cmpi sgt, %12, %c8 : index
          %16 = arith.select %15, %cst_2, %14 : f32
          %17 = arith.cmpi sgt, %12, %c16 : index
          %18 = arith.select %17, %cst_1, %16 : f32
          %19 = arith.cmpi sgt, %12, %c32 : index
          %20 = arith.select %19, %cst_0, %18 : f32
          %21 = arith.cmpi sgt, %12, %c64 : index
          %22 = arith.select %21, %cst, %20 : f32
          %23 = arith.index_cast %12 : index to i32
          %24 = arith.sitofp %23 : i32 to f32
          %25 = arith.mulf %22, %24 : f32
          %26 = arith.fptosi %25 : f32 to i32
          %27 = arith.index_cast %26 : i32 to index
          %28 = arith.maxsi %27, %c1 : index
          %29 = arith.ceildivsi %10, %28 : index
          %30 = arith.maxsi %29, %c1000 : index
          %31 = arith.minsi %10, %30 : index
          %32 = arith.ceildivsi %10, %31 : index
          %33 = arith.cmpi eq, %32, %c1 : index
          scf.if %33 {
            func.call @parallel_compute_fn(%c0, %31, %10, %c0, %9, %arg8, %8, %arg9, %arg10, %arg11, %arg12) : (index, index, index, index, index, index, index, i64, !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, i64, !llvm.ptr) -> ()
          } else {
            %34 = arith.subi %32, %c1 : index
            %35 = async.create_group %34 : !async.group
            func.call @async_dispatch_fn(%35, %c0, %32, %31, %10, %c0, %9, %arg8, %8, %arg9, %arg10, %arg11, %arg12) : (!async.group, index, index, index, index, index, index, index, index, i64, !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, i64, !llvm.ptr) -> ()
            async.await_all %35
          }
        }
      }
      return
    }
    func.func private @async_dispatch_fn(%arg0: !async.group, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: index, %arg8: index, %arg9: i64, %arg10: !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, %arg11: i64, %arg12: !llvm.ptr) {
      %c1 = arith.constant 1 : index
      %c2 = arith.constant 2 : index
      %0:2 = scf.while (%arg13 = %arg1, %arg14 = %arg2) : (index, index) -> (index, index) {
        %1 = arith.subi %arg14, %arg13 : index
        %2 = arith.cmpi sgt, %1, %c1 : index
        scf.condition(%2) %arg13, %arg14 : index, index
      } do {
      ^bb0(%arg13: index, %arg14: index):
        %1 = arith.subi %arg14, %arg13 : index
        %2 = arith.divsi %1, %c2 : index
        %3 = arith.addi %arg13, %2 : index
        %token = async.execute {
          func.call @async_dispatch_fn(%arg0, %3, %arg14, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (!async.group, index, index, index, index, index, index, index, index, i64, !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, i64, !llvm.ptr) -> ()
          async.yield
        }
        %4 = async.add_to_group %token, %arg0 : !async.token
        scf.yield %arg13, %3 : index, index
      }
      call @parallel_compute_fn(%arg1, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (index, index, index, index, index, index, index, i64, !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, i64, !llvm.ptr) -> ()
      return
    }
    func.func private @parallel_compute_fn(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: i64, %arg8: !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, %arg9: i64, %arg10: !llvm.ptr) {
      %c1 = arith.constant 1 : index
      %0 = arith.muli %arg0, %arg1 : index
      %1 = arith.addi %0, %arg1 : index
      %2 = arith.minsi %1, %arg2 : index
      %3 = arith.subi %2, %c1 : index
      %4 = arith.remsi %0, %arg2 : index
      %5 = arith.remsi %3, %arg2 : index
      %6 = arith.addi %5, %c1 : index
      scf.for %arg11 = %4 to %6 step %c1 {
        %7 = arith.muli %arg11, %arg5 : index
        %8 = arith.addi %7, %arg6 : index
        %9 = builtin.unrealized_conversion_cast %8 : index to i64
        %10 = llvm.add %9, %arg7 : i64
        %11 = llvm.extractvalue %arg8[1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
        %12 = llvm.extractvalue %arg8[2] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
        %13 = llvm.getelementptr %11[%12] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %14 = llvm.extractvalue %arg8[4, 0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
        %15 = llvm.mul %arg9, %14 overflow<nsw> : i64
        %16 = llvm.extractvalue %arg8[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
        %17 = llvm.mul %10, %16 overflow<nsw> : i64
        %18 = llvm.add %15, %17 overflow<nsw> : i64
        %19 = llvm.getelementptr inbounds %13[%18] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %20 = llvm.load %19 : !llvm.ptr -> i16
        %21 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        %22 = llvm.load %21 : !llvm.ptr -> i16
        %23 = llvm.add %20, %22 : i16
        %24 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -> !llvm.ptr, i16
        llvm.store %23, %24 : i16, !llvm.ptr
      }
      return
    }
  }
  func.func private @parallel_compute_fn(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: i64, %arg8: !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, %arg9: i64, %arg10: !llvm.ptr) {
    %c1 = arith.constant 1 : index
    %0 = arith.muli %arg0, %arg1 : index
    %1 = arith.addi %0, %arg1 : index
    %2 = arith.minsi %1, %arg2 : index
    %3 = arith.subi %2, %c1 : index
    %4 = arith.remsi %0, %arg2 : index
    %5 = arith.remsi %3, %arg2 : index
    %6 = arith.addi %5, %c1 : index
    scf.for %arg11 = %4 to %6 step %c1 {
      %7 = arith.muli %arg11, %arg5 : index
      %8 = arith.addi %7, %arg6 : index
      %9 = builtin.unrealized_conversion_cast %8 : index to i64
      %10 = llvm.add %9, %arg7 : i64
      %11 = llvm.extractvalue %arg8[1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
      %12 = llvm.extractvalue %arg8[2] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
      %13 = llvm.getelementptr %11[%12] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %14 = llvm.extractvalue %arg8[4, 0] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
      %15 = llvm.mul %arg9, %14 overflow<nsw> : i64
      %16 = llvm.extractvalue %arg8[4, 1] : !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>
      %17 = llvm.mul %10, %16 overflow<nsw> : i64
      %18 = llvm.add %15, %17 overflow<nsw> : i64
      %19 = llvm.getelementptr inbounds %13[%18] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %20 = llvm.load %19 : !llvm.ptr -> i16
      %21 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      %22 = llvm.load %21 : !llvm.ptr -> i16
      %23 = llvm.add %20, %22 : i16
      %24 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -> !llvm.ptr, i16
      llvm.store %23, %24 : i16, !llvm.ptr
    }
    return
  }
  func.func private @async_dispatch_fn(%arg0: !async.group, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: index, %arg8: index, %arg9: i64, %arg10: !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, %arg11: i64, %arg12: !llvm.ptr) {
    %c1 = arith.constant 1 : index
    %c2 = arith.constant 2 : index
    %0:2 = scf.while (%arg13 = %arg1, %arg14 = %arg2) : (index, index) -> (index, index) {
      %1 = arith.subi %arg14, %arg13 : index
      %2 = arith.cmpi sgt, %1, %c1 : index
      scf.condition(%2) %arg13, %arg14 : index, index
    } do {
    ^bb0(%arg13: index, %arg14: index):
      %1 = arith.subi %arg14, %arg13 : index
      %2 = arith.divsi %1, %c2 : index
      %3 = arith.addi %arg13, %2 : index
      %token = async.execute {
        func.call @async_dispatch_fn(%arg0, %3, %arg14, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (!async.group, index, index, index, index, index, index, index, index, i64, !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, i64, !llvm.ptr) -> ()
        async.yield
      }
      %4 = async.add_to_group %token, %arg0 : !async.token
      scf.yield %arg13, %3 : index, index
    }
    call @parallel_compute_fn(%arg1, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (index, index, index, index, index, index, index, i64, !llvm.struct<(ptr, ptr, i64, array<2 x i64>, array<2 x i64>)>, i64, !llvm.ptr) -> ()
    return
  }
}

Step to reproduce:

mlir-opt test.mlir --duplicate-function-elimination

Crash backtrace:

mlir-opt: /home/llvm-project/llvm-project-23.1.4/mlir/lib/IR/SymbolTable.cpp:691: llvm::SmallVector<{anonymous}::SymbolScope, 2> collectSymbolScopes(mlir::Operation*, mlir::Operation*): Assertion `commonAncestor && "'limit' and 'symbol' have no common ancestor"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.      Program arguments: /home/llvm-project/build-23.1.4/bin/mlir-opt /home/llvm-project/results/verify_test/178.mlir --duplicate-function-elimination
 #0 0x00005654fd37aa69 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1ea1a69)
 #1 0x00005654fd37724c llvm::sys::RunSignalHandlers() (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e9e24c)
 #2 0x00005654fd3773b2 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007fb7549cd520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007fb754a219bc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969bc)
 #5 0x00007fb7549cd476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007fb7549b37f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007fb7549b371b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007fb7549c4e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000565505d720be collectSymbolScopes(mlir::Operation*, mlir::Operation*) SymbolTable.cpp:0:0
#10 0x0000565505d734c9 llvm::LogicalResult replaceAllSymbolUsesImpl<mlir::Operation*, mlir::Operation>(mlir::Operation*, mlir::StringAttr, mlir::Operation*) SymbolTable.cpp:0:0
#11 0x0000565505d78802 mlir::SymbolUserMap::replaceAllUsesWith(mlir::Operation*, mlir::StringAttr) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa89f802)
#12 0x000056550412510d mlir::(anonymous namespace)::DuplicateFunctionEliminationPass::runOnOperation() DuplicateFunctionElimination.cpp:0:0
#13 0x00005655059ba519 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e1519)
#14 0x00005655059ba884 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e1884)
#15 0x00005655059bc902 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e3902)
#16 0x00005655059bd909 mlir::PassManager::run(mlir::Operation*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e4909)
#17 0x00005654fd43db37 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#18 0x00005654fd43e507 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, 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::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#19 0x0000565505d9ffad 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::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa8c6fad)
#20 0x00005654fd43947a mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#21 0x00005654fd43ec48 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1f65c48)
#22 0x00005654fd43eea4 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1f65ea4)
#23 0x00005654fd2c9dbc main (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1df0dbc)
#24 0x00007fb7549b4d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#25 0x00007fb7549b4e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#26 0x00005654fd35a4a5 _start (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e814a5)
Aborted (core dumped)

frida-albrecht avatar Oct 30 '26 14:10 frida-albrecht

@llvm/issue-subscribers-mlir

Author: frida-albrecht

The `--duplicate-function-elimination` pass crashes with an assertion failure when processing duplicate functions defined in different symbol scopes, including a nested `gpu.module`.

test commit: 7a941df

test case:

#map = affine_map&lt;(d0, d1, d2) -&gt; (d0, d1 - d2)&gt;
module attributes {gpu.container_module} {
  llvm.func @<!-- -->malloc(i64) -&gt; !llvm.ptr
  gpu.module @<!-- -->main_kernel_0 {
    func.func private @<!-- -->parallel_compute_fn_0(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: index, %arg8: index, %arg9: i64, %arg10: !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, %arg11: i64, %arg12: !llvm.ptr) {
      %cst = arith.constant 6.000000e-01 : f32
      %c64 = arith.constant 64 : index
      %cst_0 = arith.constant 8.000000e-01 : f32
      %c32 = arith.constant 32 : index
      %cst_1 = arith.constant 1.000000e+00 : f32
      %c16 = arith.constant 16 : index
      %cst_2 = arith.constant 2.000000e+00 : f32
      %c8 = arith.constant 8 : index
      %cst_3 = arith.constant 4.000000e+00 : f32
      %c4 = arith.constant 4 : index
      %cst_4 = arith.constant 8.000000e+00 : f32
      %c1000 = arith.constant 1000 : index
      %c0 = arith.constant 0 : index
      %c1 = arith.constant 1 : index
      %0 = arith.muli %arg0, %arg1 : index
      %1 = arith.addi %0, %arg1 : index
      %2 = arith.minsi %1, %arg2 : index
      %3 = arith.subi %2, %c1 : index
      %4 = arith.remsi %0, %arg2 : index
      %5 = arith.remsi %3, %arg2 : index
      %6 = arith.addi %5, %c1 : index
      scf.for %arg13 = %4 to %6 step %c1 {
        %7 = arith.muli %arg13, %arg5 : index
        %8 = arith.addi %arg3, %7 : index
        %9 = affine.min #map(%arg6, %arg7, %8)
        %10 = arith.ceildivsi %9, %arg8 : index
        %11 = arith.cmpi eq, %10, %c0 : index
        scf.if %11 {
        } else {
          %12 = async.runtime.num_worker_threads : index
          %13 = arith.cmpi sgt, %12, %c4 : index
          %14 = arith.select %13, %cst_3, %cst_4 : f32
          %15 = arith.cmpi sgt, %12, %c8 : index
          %16 = arith.select %15, %cst_2, %14 : f32
          %17 = arith.cmpi sgt, %12, %c16 : index
          %18 = arith.select %17, %cst_1, %16 : f32
          %19 = arith.cmpi sgt, %12, %c32 : index
          %20 = arith.select %19, %cst_0, %18 : f32
          %21 = arith.cmpi sgt, %12, %c64 : index
          %22 = arith.select %21, %cst, %20 : f32
          %23 = arith.index_cast %12 : index to i32
          %24 = arith.sitofp %23 : i32 to f32
          %25 = arith.mulf %22, %24 : f32
          %26 = arith.fptosi %25 : f32 to i32
          %27 = arith.index_cast %26 : i32 to index
          %28 = arith.maxsi %27, %c1 : index
          %29 = arith.ceildivsi %10, %28 : index
          %30 = arith.maxsi %29, %c1000 : index
          %31 = arith.minsi %10, %30 : index
          %32 = arith.ceildivsi %10, %31 : index
          %33 = arith.cmpi eq, %32, %c1 : index
          scf.if %33 {
            func.call @<!-- -->parallel_compute_fn(%c0, %31, %10, %c0, %9, %arg8, %8, %arg9, %arg10, %arg11, %arg12) : (index, index, index, index, index, index, index, i64, !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, i64, !llvm.ptr) -&gt; ()
          } else {
            %34 = arith.subi %32, %c1 : index
            %35 = async.create_group %34 : !async.group
            func.call @<!-- -->async_dispatch_fn(%35, %c0, %32, %31, %10, %c0, %9, %arg8, %8, %arg9, %arg10, %arg11, %arg12) : (!async.group, index, index, index, index, index, index, index, index, i64, !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, i64, !llvm.ptr) -&gt; ()
            async.await_all %35
          }
        }
      }
      return
    }
    func.func private @<!-- -->async_dispatch_fn(%arg0: !async.group, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: index, %arg8: index, %arg9: i64, %arg10: !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, %arg11: i64, %arg12: !llvm.ptr) {
      %c1 = arith.constant 1 : index
      %c2 = arith.constant 2 : index
      %0:2 = scf.while (%arg13 = %arg1, %arg14 = %arg2) : (index, index) -&gt; (index, index) {
        %1 = arith.subi %arg14, %arg13 : index
        %2 = arith.cmpi sgt, %1, %c1 : index
        scf.condition(%2) %arg13, %arg14 : index, index
      } do {
      ^bb0(%arg13: index, %arg14: index):
        %1 = arith.subi %arg14, %arg13 : index
        %2 = arith.divsi %1, %c2 : index
        %3 = arith.addi %arg13, %2 : index
        %token = async.execute {
          func.call @<!-- -->async_dispatch_fn(%arg0, %3, %arg14, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (!async.group, index, index, index, index, index, index, index, index, i64, !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, i64, !llvm.ptr) -&gt; ()
          async.yield
        }
        %4 = async.add_to_group %token, %arg0 : !async.token
        scf.yield %arg13, %3 : index, index
      }
      call @<!-- -->parallel_compute_fn(%arg1, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (index, index, index, index, index, index, index, i64, !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, i64, !llvm.ptr) -&gt; ()
      return
    }
    func.func private @<!-- -->parallel_compute_fn(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: i64, %arg8: !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, %arg9: i64, %arg10: !llvm.ptr) {
      %c1 = arith.constant 1 : index
      %0 = arith.muli %arg0, %arg1 : index
      %1 = arith.addi %0, %arg1 : index
      %2 = arith.minsi %1, %arg2 : index
      %3 = arith.subi %2, %c1 : index
      %4 = arith.remsi %0, %arg2 : index
      %5 = arith.remsi %3, %arg2 : index
      %6 = arith.addi %5, %c1 : index
      scf.for %arg11 = %4 to %6 step %c1 {
        %7 = arith.muli %arg11, %arg5 : index
        %8 = arith.addi %7, %arg6 : index
        %9 = builtin.unrealized_conversion_cast %8 : index to i64
        %10 = llvm.add %9, %arg7 : i64
        %11 = llvm.extractvalue %arg8[1] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
        %12 = llvm.extractvalue %arg8[2] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
        %13 = llvm.getelementptr %11[%12] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
        %14 = llvm.extractvalue %arg8[4, 0] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
        %15 = llvm.mul %arg9, %14 overflow&lt;nsw&gt; : i64
        %16 = llvm.extractvalue %arg8[4, 1] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
        %17 = llvm.mul %10, %16 overflow&lt;nsw&gt; : i64
        %18 = llvm.add %15, %17 overflow&lt;nsw&gt; : i64
        %19 = llvm.getelementptr inbounds %13[%18] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
        %20 = llvm.load %19 : !llvm.ptr -&gt; i16
        %21 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
        %22 = llvm.load %21 : !llvm.ptr -&gt; i16
        %23 = llvm.add %20, %22 : i16
        %24 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
        llvm.store %23, %24 : i16, !llvm.ptr
      }
      return
    }
  }
  func.func private @<!-- -->parallel_compute_fn(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: i64, %arg8: !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, %arg9: i64, %arg10: !llvm.ptr) {
    %c1 = arith.constant 1 : index
    %0 = arith.muli %arg0, %arg1 : index
    %1 = arith.addi %0, %arg1 : index
    %2 = arith.minsi %1, %arg2 : index
    %3 = arith.subi %2, %c1 : index
    %4 = arith.remsi %0, %arg2 : index
    %5 = arith.remsi %3, %arg2 : index
    %6 = arith.addi %5, %c1 : index
    scf.for %arg11 = %4 to %6 step %c1 {
      %7 = arith.muli %arg11, %arg5 : index
      %8 = arith.addi %7, %arg6 : index
      %9 = builtin.unrealized_conversion_cast %8 : index to i64
      %10 = llvm.add %9, %arg7 : i64
      %11 = llvm.extractvalue %arg8[1] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
      %12 = llvm.extractvalue %arg8[2] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
      %13 = llvm.getelementptr %11[%12] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
      %14 = llvm.extractvalue %arg8[4, 0] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
      %15 = llvm.mul %arg9, %14 overflow&lt;nsw&gt; : i64
      %16 = llvm.extractvalue %arg8[4, 1] : !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;
      %17 = llvm.mul %10, %16 overflow&lt;nsw&gt; : i64
      %18 = llvm.add %15, %17 overflow&lt;nsw&gt; : i64
      %19 = llvm.getelementptr inbounds %13[%18] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
      %20 = llvm.load %19 : !llvm.ptr -&gt; i16
      %21 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
      %22 = llvm.load %21 : !llvm.ptr -&gt; i16
      %23 = llvm.add %20, %22 : i16
      %24 = llvm.getelementptr inbounds|nuw %arg10[%10] : (!llvm.ptr, i64) -&gt; !llvm.ptr, i16
      llvm.store %23, %24 : i16, !llvm.ptr
    }
    return
  }
  func.func private @<!-- -->async_dispatch_fn(%arg0: !async.group, %arg1: index, %arg2: index, %arg3: index, %arg4: index, %arg5: index, %arg6: index, %arg7: index, %arg8: index, %arg9: i64, %arg10: !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, %arg11: i64, %arg12: !llvm.ptr) {
    %c1 = arith.constant 1 : index
    %c2 = arith.constant 2 : index
    %0:2 = scf.while (%arg13 = %arg1, %arg14 = %arg2) : (index, index) -&gt; (index, index) {
      %1 = arith.subi %arg14, %arg13 : index
      %2 = arith.cmpi sgt, %1, %c1 : index
      scf.condition(%2) %arg13, %arg14 : index, index
    } do {
    ^bb0(%arg13: index, %arg14: index):
      %1 = arith.subi %arg14, %arg13 : index
      %2 = arith.divsi %1, %c2 : index
      %3 = arith.addi %arg13, %2 : index
      %token = async.execute {
        func.call @<!-- -->async_dispatch_fn(%arg0, %3, %arg14, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (!async.group, index, index, index, index, index, index, index, index, i64, !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, i64, !llvm.ptr) -&gt; ()
        async.yield
      }
      %4 = async.add_to_group %token, %arg0 : !async.token
      scf.yield %arg13, %3 : index, index
    }
    call @<!-- -->parallel_compute_fn(%arg1, %arg3, %arg4, %arg5, %arg6, %arg7, %arg8, %arg9, %arg10, %arg11, %arg12) : (index, index, index, index, index, index, index, i64, !llvm.struct&lt;(ptr, ptr, i64, array&lt;2 x i64&gt;, array&lt;2 x i64&gt;)&gt;, i64, !llvm.ptr) -&gt; ()
    return
  }
}

Step to reproduce:

mlir-opt test.mlir --duplicate-function-elimination

Crash backtrace:

mlir-opt: /home/llvm-project/llvm-project-23.1.4/mlir/lib/IR/SymbolTable.cpp:691: llvm::SmallVector&lt;{anonymous}::SymbolScope, 2&gt; collectSymbolScopes(mlir::Operation*, mlir::Operation*): Assertion `commonAncestor &amp;&amp; "'limit' and 'symbol' have no common ancestor"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.      Program arguments: /home/llvm-project/build-23.1.4/bin/mlir-opt /home/llvm-project/results/verify_test/178.mlir --duplicate-function-elimination
 #<!-- -->0 0x00005654fd37aa69 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1ea1a69)
 #<!-- -->1 0x00005654fd37724c llvm::sys::RunSignalHandlers() (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e9e24c)
 #<!-- -->2 0x00005654fd3773b2 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #<!-- -->3 0x00007fb7549cd520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #<!-- -->4 0x00007fb754a219bc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969bc)
 #<!-- -->5 0x00007fb7549cd476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #<!-- -->6 0x00007fb7549b37f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #<!-- -->7 0x00007fb7549b371b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #<!-- -->8 0x00007fb7549c4e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #<!-- -->9 0x0000565505d720be collectSymbolScopes(mlir::Operation*, mlir::Operation*) SymbolTable.cpp:0:0
#<!-- -->10 0x0000565505d734c9 llvm::LogicalResult replaceAllSymbolUsesImpl&lt;mlir::Operation*, mlir::Operation&gt;(mlir::Operation*, mlir::StringAttr, mlir::Operation*) SymbolTable.cpp:0:0
#<!-- -->11 0x0000565505d78802 mlir::SymbolUserMap::replaceAllUsesWith(mlir::Operation*, mlir::StringAttr) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa89f802)
#<!-- -->12 0x000056550412510d mlir::(anonymous namespace)::DuplicateFunctionEliminationPass::runOnOperation() DuplicateFunctionElimination.cpp:0:0
#<!-- -->13 0x00005655059ba519 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e1519)
#<!-- -->14 0x00005655059ba884 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e1884)
#<!-- -->15 0x00005655059bc902 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e3902)
#<!-- -->16 0x00005655059bd909 mlir::PassManager::run(mlir::Operation*) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa4e4909)
#<!-- -->17 0x00005654fd43db37 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->18 0x00005654fd43e507 llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::'lambda'(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, llvm::raw_ostream&amp;)&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->19 0x0000565505d9ffad mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0xa8c6fad)
#<!-- -->20 0x00005654fd43947a mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (.part.0) MlirOptMain.cpp:0:0
#<!-- -->21 0x00005654fd43ec48 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1f65c48)
#<!-- -->22 0x00005654fd43eea4 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1f65ea4)
#<!-- -->23 0x00005654fd2c9dbc main (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1df0dbc)
#<!-- -->24 0x00007fb7549b4d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#<!-- -->25 0x00007fb7549b4e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#<!-- -->26 0x00005654fd35a4a5 _start (/home/llvm-project/build-23.1.4/bin/mlir-opt+0x1e814a5)
Aborted (core dumped)

Retested on the latest LLVM revision (880b33a), and the issue is no longer reproducible.

frida-albrecht avatar Nov 02 '26 14:11 frida-albrecht

I confirmed that this crash is fixed by #209667.

Men-cotton avatar Nov 02 '26 20:11 Men-cotton