Skip to content

[MLIR] Invalid scf -> cf lowering when the scf.index_switch case values are greater than i32 #111589

@Kuree

Description

@Kuree

Input:

func.func @foo(%arg: index) {
    scf.index_switch %arg
    case 4294967296 { // 2^32
      "op.op"() : () -> ()
      scf.yield
    }
    case 8589934592 { // 2^33
      "op.op"() : () -> ()
      scf.yield
    }
    default {
      "op.op"() : () -> ()
      scf.yield
    }
    return
}

Using latest mlir-opt

// mlir-opt --convert-scf-to-cf --allow-unregistered-dialect
module {
  func.func @foo(%arg0: index) {
    %0 = arith.index_cast %arg0 : index to i32
    cf.switch %0 : i32, [
      default: ^bb3,
      0: ^bb1,
      0: ^bb2
    ]
  ^bb1:  // pred: ^bb0
    "op.op"() : () -> ()
    cf.br ^bb4
  ^bb2:  // pred: ^bb0
    "op.op"() : () -> ()
    cf.br ^bb4
  ^bb3:  // pred: ^bb0
    "op.op"() : () -> ()
    cf.br ^bb4
  ^bb4:  // 3 preds: ^bb1, ^bb2, ^bb3
    return
  }
}

This is caused by an overflow here:

, where the case values are actually int64_t.

Link to Goldbolt: https://godbolt.org/z/bvbW51WM4

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