[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 20:21:38 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:

Thanks for the update! It seems to be the right direction to me, though there is a couple of missing things:
1. I think we need to make sure that we still call the `_FortranAcpowi` and other Fortran runtime functions for Flang, so I think we need to have a pass that will convert the complex pow operations back to Fortran runtime calls (unless the ROCDL conversion converts them to AMD GPU specific code).
2. I would suggest introducing powi operation in the Complex dialect, so that we know that the exponent argument is an integer value 100%.  If there is a way to guarantee that we always recognize `complex.pow`'s integer exponent argument whenever Flang created such an operation, then `powi` is redundant.  So it depends on how reliable the recognition is.

https://github.com/llvm/llvm-project/pull/153183


More information about the flang-commits mailing list