@@ -1287,6 +1287,26 @@ mlir::Value genComplexMathOp(fir::FirOpBuilder &builder, mlir::Location loc,
12871287 return result;
12881288}
12891289
1290+ mlir::Value genComplexPow (fir::FirOpBuilder &builder, mlir::Location loc,
1291+ const MathOperation &mathOp,
1292+ mlir::FunctionType mathLibFuncType,
1293+ llvm::ArrayRef<mlir::Value> args) {
1294+ bool isAMDGPU = fir::getTargetTriple (builder.getModule ()).isAMDGCN ();
1295+ if (!isAMDGPU)
1296+ return genLibCall (builder, loc, mathOp, mathLibFuncType, args);
1297+
1298+ auto complexTy = mlir::cast<mlir::ComplexType>(mathLibFuncType.getInput (0 ));
1299+ auto realTy = complexTy.getElementType ();
1300+ mlir::Value realExp = builder.createConvert (loc, realTy, args[1 ]);
1301+ mlir::Value zero = builder.createRealConstant (loc, realTy, 0 );
1302+ mlir::Value complexExp =
1303+ builder.create <mlir::complex ::CreateOp>(loc, complexTy, realExp, zero);
1304+ mlir::Value result =
1305+ builder.create <mlir::complex ::PowOp>(loc, args[0 ], complexExp);
1306+ result = builder.createConvert (loc, mathLibFuncType.getResult (0 ), result);
1307+ return result;
1308+ }
1309+
12901310// / Mapping between mathematical intrinsic operations and MLIR operations
12911311// / of some appropriate dialect (math, complex, etc.) or libm calls.
12921312// / TODO: support remaining Fortran math intrinsics.
@@ -1636,15 +1656,19 @@ static constexpr MathOperation mathOperations[] = {
16361656 genFuncType<Ty::Real<16 >, Ty::Real<16 >, Ty::Integer<8 >>,
16371657 genMathOp<mlir::math::FPowIOp>},
16381658 {" pow" , RTNAME_STRING (cpowi),
1639- genFuncType<Ty::Complex<4 >, Ty::Complex<4 >, Ty::Integer<4 >>, genLibCall},
1659+ genFuncType<Ty::Complex<4 >, Ty::Complex<4 >, Ty::Integer<4 >>,
1660+ genComplexPow},
16401661 {" pow" , RTNAME_STRING (zpowi),
1641- genFuncType<Ty::Complex<8 >, Ty::Complex<8 >, Ty::Integer<4 >>, genLibCall},
1662+ genFuncType<Ty::Complex<8 >, Ty::Complex<8 >, Ty::Integer<4 >>,
1663+ genComplexPow},
16421664 {" pow" , RTNAME_STRING (cqpowi), FuncTypeComplex16Complex16Integer4,
16431665 genLibF128Call},
16441666 {" pow" , RTNAME_STRING (cpowk),
1645- genFuncType<Ty::Complex<4 >, Ty::Complex<4 >, Ty::Integer<8 >>, genLibCall},
1667+ genFuncType<Ty::Complex<4 >, Ty::Complex<4 >, Ty::Integer<8 >>,
1668+ genComplexPow},
16461669 {" pow" , RTNAME_STRING (zpowk),
1647- genFuncType<Ty::Complex<8 >, Ty::Complex<8 >, Ty::Integer<8 >>, genLibCall},
1670+ genFuncType<Ty::Complex<8 >, Ty::Complex<8 >, Ty::Integer<8 >>,
1671+ genComplexPow},
16481672 {" pow" , RTNAME_STRING (cqpowk), FuncTypeComplex16Complex16Integer8,
16491673 genLibF128Call},
16501674 {" remainder" , " remainderf" ,
@@ -4044,21 +4068,20 @@ void IntrinsicLibrary::genExecuteCommandLine(
40444068 mlir::Value waitAddr = fir::getBase (wait);
40454069 mlir::Value waitIsPresentAtRuntime =
40464070 builder.genIsNotNullAddr (loc, waitAddr);
4047- waitBool = builder
4048- .genIfOp (loc, {i1Ty}, waitIsPresentAtRuntime,
4049- /* withElseRegion=*/ true )
4050- .genThen ([&]() {
4051- auto waitLoad =
4052- fir::LoadOp::create (builder, loc, waitAddr);
4053- mlir::Value cast =
4054- builder.createConvert (loc, i1Ty, waitLoad);
4055- fir::ResultOp::create (builder, loc, cast);
4056- })
4057- .genElse ([&]() {
4058- mlir::Value trueVal = builder.createBool (loc, true );
4059- fir::ResultOp::create (builder, loc, trueVal);
4060- })
4061- .getResults ()[0 ];
4071+ waitBool =
4072+ builder
4073+ .genIfOp (loc, {i1Ty}, waitIsPresentAtRuntime,
4074+ /* withElseRegion=*/ true )
4075+ .genThen ([&]() {
4076+ auto waitLoad = fir::LoadOp::create (builder, loc, waitAddr);
4077+ mlir::Value cast = builder.createConvert (loc, i1Ty, waitLoad);
4078+ fir::ResultOp::create (builder, loc, cast);
4079+ })
4080+ .genElse ([&]() {
4081+ mlir::Value trueVal = builder.createBool (loc, true );
4082+ fir::ResultOp::create (builder, loc, trueVal);
4083+ })
4084+ .getResults ()[0 ];
40624085 }
40634086
40644087 mlir::Value exitstatBox =
0 commit comments