Lower to the LLVM dialect the math operations

I’m trying to lower to the LLVM dialect the math operations such as math::cos.
I used mlir::populateMathToLLVMConversionPatterns(typeConverter, patterns) (the function from the <mlir/Conversion/MathToLLVM/MathToLLVM.h> header).
But with a newer version of LLVM I no longer get, for example,
%24 = math.cos %23 : f16
converted to
%36 = “llvm.intr.cos”(%35) : (f16) → f16
as I used to get it converted with the older version of LLVM that I used. It simply stays unconverted.

Could you please tell me how can I perform the conversion as shown above with the mlir::populateMathToLLVMConversionPatterns() function in the newer versions of LLVM?

Thank you very much.

Have you tried debugging? Was is the log of running with --debug-only=dialect-conversion?
You’re not provided a reproducer using the -convert-math-to-llvm so it’s hard to say what’s the problem…

Hello, Mehdi,
Thank you for the information.
Indeed I used -debug-only=dialect-conversion for my mlir-opt equivalent executable. And I found in the debug information printed that, for example, math.cos is considered legal and that’s why it is not converted to the LLVM dialect. Then I remembered that I wrote the following in the code:
So, I commented the above line and then it ran successfully the conversion of the math.cos op to the LLVM dialect.
Thank you,

1 Like