[flang-commits] [flang] [mlir] [MLIR] Add cpow support in ComplexToROCDLLibraryCalls (PR #153183)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Mon Aug 18 09:28:03 PDT 2025
================
@@ -1625,15 +1655,19 @@ static constexpr MathOperation mathOperations[] = {
genFuncType<Ty::Real<16>, Ty::Real<16>, Ty::Integer<8>>,
genMathOp<mlir::math::FPowIOp>},
{"pow", RTNAME_STRING(cpowi),
- genFuncType<Ty::Complex<4>, Ty::Complex<4>, Ty::Integer<4>>, genLibCall},
+ genFuncType<Ty::Complex<4>, Ty::Complex<4>, Ty::Integer<4>>,
+ genComplexPow},
----------------
vzakhari wrote:
Please look at how this case works:
```
{"pow", RTNAME_STRING(FPow4i),
genFuncType<Ty::Real<4>, Ty::Real<4>, Ty::Integer<4>>,
genMathOp<mlir::math::FPowIOp>},
```
Depending on the `mathRuntimeVersion` Flang either generates a call to `_FortranAFPow4i` or an `mlir::math::FPowIOp` operation. You can do the same for `_FortranAcpowi` vs `complex.pow`, and then handle `complex.pow` any way you wish later in the pipeline. So for AMD GPU you may convert it to the ocml calls, and otherwise you may convert it to `_FortranAcpowi` late in Flang pass pipeline. This way, we get all the benefits of not having a call with side effects at MLIR level, and we can apply folding/canonicalization to `complex.pow`.
https://github.com/llvm/llvm-project/pull/153183
More information about the flang-commits
mailing list