[flang-commits] [flang] [flang] Fix for atand(Y, X), and implment atan2d(Y, X) (PR #79002)
via flang-commits
flang-commits at lists.llvm.org
Tue Jan 23 09:40:55 PST 2024
================
@@ -2128,13 +2129,53 @@ IntrinsicLibrary::genAny(mlir::Type resultType,
return readAndAddCleanUp(resultMutableBox, resultType, "ANY");
}
+// ATAN2D
+mlir::Value IntrinsicLibrary::genAtan2d(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 2);
+
+ mlir::Value y = fir::getBase(args[0]);
+ mlir::Value x = fir::getBase(args[1]);
+
+ // When Y == 0 X must not be 0
+ mlir::Value zero = builder.createRealZeroConstant(loc, y.getType());
+ mlir::Value cmpYEq0 = builder.create<mlir::arith::CmpFOp>(
+ loc, mlir::arith::CmpFPredicate::UEQ, y, zero);
----------------
jeanPerier wrote:
I actually do not see why the check is done for atan2d but not atand. The standard also says _"If Y has the value zero, X shall not have the value zero"_ for ATAND in your quote.
Note that the same requirement exists for ATAN2/ATAN and is not enforced. I would advise not enforcing this user constraint without some error checking flag due to the potential performance cost inside numerical kernel.
So you can probably just set genAtand as the handler for genAtan2d and save the duplication.
https://github.com/llvm/llvm-project/pull/79002
More information about the flang-commits
mailing list