Failed to materialize conversion

func.func @main(){
%0 = “tosa.constant”() {value = dense<[[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () → tensor<2x3xf64>
%1 = “tosa.constant”() {value = dense<[[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () → tensor<2x3xf64>
%2 = “tosa.add”(%0,%1):(tensor<2x3xf64>,tensor<2x3xf64>) → tensor<2x3xf64>

return

}
This mlir code is lowering well but can’t lower this code
func.func @main()-> tensor<2x3xf64> {
%0 = “tosa.constant”() {value = dense<[[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () → tensor<2x3xf64>
%1 = “tosa.constant”() {value = dense<[[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>} : () → tensor<2x3xf64>
%2 = “tosa.add”(%0,%1):(tensor<2x3xf64>,tensor<2x3xf64>) → tensor<2x3xf64>

return %2 : tensor<2x3xf64>

}

build/bin/hello-opt --mlir-print-ir-after-all test/Hello/print.mlir
loc(“test/Hello/print.mlir”:7:10): error: failed to materialize conversion for result #0 of operation ‘hello.add’ that remained live after conversion
// -----// IR Dump After {anonymous}::HelloToAffineLowerPass Failed () //----- //
module {
func.func @main() → tensor<2x3xf64> {
%0 = “hello.constant”() <{value = dense<[[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>}> : () → tensor<2x3xf64>
%1 = “hello.constant”() <{value = dense<[[1.000000e+00, 2.000000e+00, 3.000000e+00], [4.000000e+00, 5.000000e+00, 6.000000e+00]]> : tensor<2x3xf64>}> : () → tensor<2x3xf64>
%2 = “hello.add”(%0, %1) : (tensor<2x3xf64>, tensor<2x3xf64>) → tensor<2x3xf64>
return %2 : tensor<2x3xf64>
}
}

why?
why is it giving conversion error?

@rkayaith could you please help.

It seems like your HelloToAffineLower pass considers hello.add as illegal, but doesn’t have a conversion set up for it. The one that “works” may have only succeeded because the tosa.add output is unused, if you look at the resulting IR you’ll probably find that all the ops have been DCE’d.

Without seeing the source for the pass it’s hard to give more specific advice, but you can read more about dialect conversion here: