[llvm] [DirectX] Add atan2 intrinsic and expand for DXIL backend (p1) (PR #108865)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 16 11:09:39 PDT 2024
================
@@ -305,6 +306,48 @@ static Value *expandNormalizeIntrinsic(CallInst *Orig) {
return Builder.CreateFMul(X, MultiplicandVec);
}
+static Value *expandAtan2Intrinsic(CallInst *Orig) {
+ Value *Y = Orig->getOperand(0);
+ Value *X = Orig->getOperand(1);
+ Type *Ty = X->getType();
+ IRBuilder<> Builder(Orig);
+
+ Value *Tan = Builder.CreateFDiv(Y, X);
+
+ Value *Atan =
+ Builder.CreateIntrinsic(Ty, Intrinsic::atan, {Tan}, nullptr, "Elt.Atan");
+
+ Constant *Pi = ConstantFP::get(Ty, llvm::numbers::pi);
+ Constant *HalfPi = ConstantFP::get(Ty, llvm::numbers::pi / 2);
+ Constant *NegHalfPi = ConstantFP::get(Ty, -llvm::numbers::pi / 2);
+ Constant *Zero = ConstantFP::get(Ty, 0);
+
+ Value *AtanAddPi = Builder.CreateFAdd(Atan, Pi);
+ Value *AtanSubPi = Builder.CreateFSub(Atan, Pi);
+
+ Value *Result = Atan;
+
+ Value *XLt0 = Builder.CreateFCmpOLT(X, Zero);
----------------
farzonl wrote:
can you add some comments and group the `atan`, `atan + pi`, `atan - pi`, `atan + pi/2`, and `atan - pi/2` cases.
https://github.com/llvm/llvm-project/pull/108865
More information about the llvm-commits
mailing list