Skip to content

[mlir] Ordering of lowering passes to convert different dialects to llvm may lead to conversion failute #55028

Open
@sahas3

Description

@sahas3

Input MLIR in TOSA dialect:

module  {
  func @main(%arg0: tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32> {
    %0 = "tosa.clamp"(%arg0) {max_fp = 3.40282347E+38 : f32, max_int = 2147483647 : i64, min_fp = 0.000000e+00 : f32, min_int = 0 : i64} : (tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32>
    return %0 : tensor<1x2x2x3xf32>
  }
}

Pipeline pass to convert to LLVM-IR:

mlir-opt network.mlir --pass-pipeline="func.func(tosa-infer-shapes, tosa-to-linalg-named, tosa-to-linalg, canonicalize, arith-expand, canonicalize)" --one-shot-bufferize="allow-return-allocs allow-unknown-ops create-deallocs=0" --func-bufferize --pass-pipeline="func.func(canonicalize, convert-linalg-to-affine-loops, affine-loop-fusion, lower-affine, finalizing-bufferize, buffer-deallocation, convert-scf-to-cf, convert-math-to-llvm)" --convert-arith-to-llvm --convert-vector-to-llvm --convert-cf-to-llvm --convert-memref-to-llvm --convert-func-to-llvm --canonicalize --reconcile-unrealized-casts --canonicalize --llvm-legalize-for-export > network-llvm.mlir

leads to a failure after --convert-cf-to-llvm

network.mlir:3:10: error: type mismatch for bb argument #0 of successor #0 
%0 = "tosa.clamp"(%arg0) {max_fp = 3.40282347E+38 : f32, max_int = 2147483647 : i64, min_fp = 0.000000e+00 : f32, min_int = 0 : i64} : (tensor<1x2x2x3xf32>) -> tensor<1x2x2x3xf32>                                                                  ^                                                                                                              
network.mlir:3:10: note: see current operation: "llvm.br"(%3)[^bb1] : (i64) -> ()

Moving --convert-cf-to-llvm after --convert-func-to-llvm succeeds. This looks like a bug as ordering of lowering passes shouldn't matter.

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