[flang-commits] [flang] [flang] IEEE_SCALB and SCALE - kind=2, kind=3 (PR #135374)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Fri Apr 11 09:09:28 PDT 2025
================
@@ -7593,12 +7593,46 @@ IntrinsicLibrary::genSameTypeAs(mlir::Type resultType,
mlir::Value IntrinsicLibrary::genScale(mlir::Type resultType,
llvm::ArrayRef<mlir::Value> args) {
assert(args.size() == 2);
+ mlir::FloatType floatTy = mlir::dyn_cast<mlir::FloatType>(resultType);
+ if (!floatTy.isF16() && !floatTy.isBF16()) // kind=4,8,10,16
+ return builder.createConvert(
+ loc, resultType,
+ fir::runtime::genScale(builder, loc, args[0], args[1]));
- mlir::Value realX = fir::getBase(args[0]);
- mlir::Value intI = fir::getBase(args[1]);
-
- return builder.createConvert(
- loc, resultType, fir::runtime::genScale(builder, loc, realX, intI));
+ // Convert kind=2,3 arg X to kind=4. Convert kind=4 result back to kind=2,3.
+ mlir::Type i1Ty = builder.getI1Type();
+ mlir::Type f32Ty = mlir::Float32Type::get(builder.getContext());
+ mlir::Value result = builder.createConvert(
+ loc, resultType,
+ fir::runtime::genScale(
+ builder, loc, builder.createConvert(loc, f32Ty, args[0]), args[1]));
+
+ // kind=4 runtime::genScale call may not signal kind=2,3 exceptions.
----------------
vzakhari wrote:
It makese sence for `IEEE_SCALB`, but is this really needed for implementing `SCALE` intrinsic? I would prefer doing the extra work only for `IEEE_SCALB`.
https://github.com/llvm/llvm-project/pull/135374
More information about the flang-commits
mailing list