llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.6k stars 11.34k forks source link

[MLIR] `scf.index_switch` fold does not converge #98535

Closed Kuree closed 1 month ago

Kuree commented 1 month ago

Edit: found a much smaller input.

Input:

// RUN: mlir-opt --allow-unregistered-dialect  --canonicalize %s
func.func @foo() {
  %c0 = arith.constant 0 : index
  scf.index_switch %c0 
  case 0 {
    scf.yield
  }
  default {
    "op.op"() : () -> ()
    scf.yield
  }
  return
}

See godbolt link that uses trunk: https://godbolt.org/z/1fcT87E17

Kuree commented 1 month ago

Based on the documentation on folder, it says:

/// Note that this mechanism cannot be used to remove 0-result operations.
LogicalResult MyOp::fold(FoldAdaptor adaptor,
                         SmallVectorImpl<OpFoldResult> &results) {
  ...
}

It seems like we are not allowed to fold if the scf.index_switch op has no results. I can send a PR to fix this.

Kuree commented 1 month ago

Fixed by https://github.com/llvm/llvm-project/pull/98680