Skip to content

[MLIR] RemoveDeadValues pass errors when run on private function #158760

@Sirraide

Description

@Sirraide

Consider (https://godbolt.org/z/W95n8jEvM):

func.func private @test(%arg0: i64) -> (i64) {
    %c0_i64 = arith.constant 0 : i64
    %2 = arith.cmpi eq, %arg0, %c0_i64 : i64
    cf.cond_br %2, ^bb1, ^bb2
  ^bb1:  // pred: ^bb0
    %c1_i64 = arith.constant 1 : i64
    return %c1_i64 : i64
  ^bb2:  // pred: ^bb0
    %c3_i64 = arith.constant 3 : i64
    return %c3_i64 : i64
}

Running mlir-opt --remove-dead-values results in the following error:

<source>:4:5: error: 'cf.cond_br' op expected 1 or more operands, but found 0
    cf.cond_br %2, ^bb1, ^bb2
    ^
<source>:4:5: note: see current operation: "cf.cond_br"()[^bb1, ^bb2] <{operandSegmentSizes = array<i32: 1, 0, 0>}> : () -> ()

The input I had before reduction instead causes it to complain about a ‘null operand’, but I presume the bug is the same (https://godbolt.org/z/cM14hjqjh):

func.func private @test(%arg0: i64) {
    %0 = "custom.slot"() <{alignment = 8 : i64, bytes = 8 : i64}> : () -> !llvm.ptr
    "custom.store"(%0, %arg0) <{alignment = 8 : i64}> : (!llvm.ptr, i64) -> ()
    %1 = "custom.load"(%0) <{alignment = 8 : i64}> : (!llvm.ptr) -> i64
    %c0_i64 = arith.constant 0 : i64
    %2 = arith.cmpi eq, %1, %c0_i64 : i64
    cf.cond_br %2, ^bb1, ^bb2
  ^bb1:  // pred: ^bb0
    %c1_i64 = arith.constant 1 : i64
    "custom.ret"(%c1_i64) : (i64) -> ()
  ^bb2:  // pred: ^bb0
    %c3_i64 = arith.constant 3 : i64
    "custom.ret"(%c3_i64) : (i64) -> ()
}

Error message:

<source>:7:5: error: null operand found
    cf.cond_br %2, ^bb1, ^bb2
    ^
<source>:7:5: note: see current operation: "cf.cond_br"(<<NULL VALUE>>)[^bb1, ^bb2] <{operandSegmentSizes = array<i32: 1, 0, 0>}> : (<<NULL TYPE>>) -> ()

In both cases, removing private causes the error to disappear.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions