Skip to content

Commit 139bf5b

Browse files
committed
[ConstantFold] Special case atan +/-0.0
C's Annex F specifies that atan +/-0.0 returns the input value; however, this behavior is optional and host C libraries may behave differently. This change applies the Annex F behavior to constant folding by LLVM. Ref: https://pubs.opengroup.org/onlinepubs/9799919799/functions/atan.html
1 parent 1bb408a commit 139bf5b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
25492549
case Intrinsic::cosh:
25502550
return ConstantFoldFP(cosh, APF, Ty);
25512551
case Intrinsic::atan:
2552+
// Implement optional behavior from C's Annex F for +/-0.0.
2553+
if (U.isZero())
2554+
return ConstantFP::get(Ty->getContext(), U);
25522555
return ConstantFoldFP(atan, APF, Ty);
25532556
case Intrinsic::sqrt:
25542557
return ConstantFoldFP(sqrt, APF, Ty);

0 commit comments

Comments
 (0)