This is an archive of the discontinued LLVM Phabricator instance.

[mlir][complex] Add pow/sqrt/tanh ops and lowering to libm
ClosedPublic

Authored by bkramer on May 13 2022, 8:17 AM.

Details

Summary

Lowering through libm gives us a baseline version, even though it's not
going to be particularly fast. This is similar to what we do for some
math dialect ops.

Diff Detail

Event Timeline

bkramer created this revision.May 13 2022, 8:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2022, 8:17 AM
bkramer requested review of this revision.May 13 2022, 8:17 AM
ftynse accepted this revision.May 17 2022, 7:31 AM
This revision is now accepted and ready to land.May 17 2022, 7:31 AM

I think there's an ABI issue here, MLIR complex numbers are always lowered to an LLVM struct of 2 elements, but that isn't necessarily the correct platform ABI for passing complex numbers/C structs (C complex numbers and C structs have the same ABI).
I see an issue with complex<f32> on x86_64: cpow expects both arguments to be passed in %xmm0 (i,e, [2 x float] at the LLVM level) but here they are passed in %xmm0 and %xmm1 ({float, float} at the LLVM level)

I'm not sure what the fix is here. Does MLIR have target awareness that we can switch on to lower to the correct thing when the ABI is different?

I think there's an ABI issue here, MLIR complex numbers are always lowered to an LLVM struct of 2 elements, but that isn't necessarily the correct platform ABI for passing complex numbers/C structs (C complex numbers and C structs have the same ABI).
I see an issue with complex<f32> on x86_64: cpow expects both arguments to be passed in %xmm0 (i,e, [2 x float] at the LLVM level) but here they are passed in %xmm0 and %xmm1 ({float, float} at the LLVM level)

I'm not sure what the fix is here. Does MLIR have target awareness that we can switch on to lower to the correct thing when the ABI is different?

I was afraid this would happen. As far as I know MLIR doesn't have a way of using the correct ABI. The only place that has this information in LLVM is in Clang.

We probably just have to add non-libm expansions for all the ops.

I was afraid this would happen. As far as I know MLIR doesn't have a way of using the correct ABI. The only place that has this information in LLVM is in Clang.

We probably just have to add non-libm expansions for all the ops.

I posted about this on discourse too, maybe we could start a discussion there? https://discourse.llvm.org/t/complex-to-libm-conversion-abi-issues/65131

Thanks!