[flang-commits] [flang] [flang] Fix for atand(Y, X), and implment atan2d(Y, X) (PR #79002)

Yi Wu via flang-commits flang-commits at lists.llvm.org
Mon Jan 22 08:33:01 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);
----------------
yi-wu-arm wrote:

I can change the check logic
from 
```cpp
bool YEq0 = y==0;
bool XEq0 = x==0;
bool terminationCheck = YEq0==XEq0;
if(terminationCheck) termination;
```
to
```cpp
bool YEq0 = y==0;
if(YEq0){
  bool XEq0 = x==0;
  if(XEq0) termination;
}
```
but I don't know if thats worth it

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


More information about the flang-commits mailing list