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

[MLIR][transforms] Error in `cloneInto()` function when null values exist in pass `RemoveDeadValues`

Open srishti-pm opened this issue 3 years ago • 4 comments

The pass RemoveDeadValues uses the cloneInto() function to copy one region to the other during a specific cleanup. This function in turn uses the function setOperands(). The latter cannot handle the presence of null values inside the source region, which has the potential to cause an error when we apply this pass. Null values are expected to appear during the execution of this pass, although it is ensured that at the end of the pass, all such values are removed.

To fix this error, a replacement for the cloneInto() function needs to be found.

Example input:

func.func @clean_region_branch_op_remove_last_2_results_last_2_arguments_and_last_operand(%arg2: i1) -> (i32) {
  %c0 = arith.constant 0 : i32
  %c1 = arith.constant 1 : i32
  %c2 = arith.constant 2 : i32
  %live, %non_live, %non_live_0, %non_live_1 = scf.while (%arg3 = %c0, %arg4 = %c1, %arg10 = %c2) : (i32, i32, i32) -> (i32, i32, i32, i32) {
    %non_live_2 = arith.addi %arg10, %arg10 : i32
    %non_live_3 = func.call @identity(%arg10) : (i32) -> (i32)
    scf.condition(%arg2) %arg4, %arg3, %non_live_2, %non_live_3 : i32, i32, i32, i32
  } do {
  ^bb0(%arg5: i32, %arg6: i32, %arg7: i32, %arg8: i32):
    %non_live_4 = arith.addi %arg7, %arg8 :i32
    scf.yield %arg5, %arg6, %non_live_4 : i32, i32, i32
  }
  return %live : i32
}
func.func private @identity(%arg1 : i32) -> (i32) {
  return %arg1 : i32
}

Error trace:

0x000055555b962f6f in mlir::detail::OperandStorage::setOperands(mlir::Operation*, mlir::ValueRange) ()
(gdb) backtrace
#0  0x000055555b962f6f in mlir::detail::OperandStorage::setOperands(mlir::Operation*, mlir::ValueRange) ()
#1  0x000055555b96a163 in mlir::Region::cloneInto(mlir::Region*, llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, false, false, void>, false, false>, mlir::IRMapping&) ()
#2  0x000055555b30e4f6 in (anonymous namespace)::dropUsesAndEraseResults(mlir::Operation*, llvm::BitVector) ()
#3  0x000055555b30db70 in (anonymous namespace)::RemoveDeadValues::runOnOperation()::$_1::operator()(mlir::Operation*) const ()

srishti-pm avatar Aug 25 '23 22:08 srishti-pm

@llvm/issue-subscribers-mlir

llvmbot avatar Aug 25 '23 22:08 llvmbot

I'm currently working on fixing this error.

srishti-pm avatar Aug 25 '23 22:08 srishti-pm

Upstream LLVM patch for fixing this error: https://reviews.llvm.org/D158941. Will be submitted soon.

srishti-pm avatar Aug 26 '23 18:08 srishti-pm

Landed https://reviews.llvm.org/D158941.

srishti-pm avatar Aug 26 '23 19:08 srishti-pm