[llvm] [ConstantFold] Special case atan +/-0.0 (PR #143962)
Lei Huang via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 12 13:13:11 PDT 2025
https://github.com/lei137 created https://github.com/llvm/llvm-project/pull/143962
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
>From 1bb408adb38cf7316073df3cd71939a748e6626d Mon Sep 17 00:00:00 2001
From: Lei Huang <lei at ca.ibm.com>
Date: Wed, 11 Jun 2025 14:17:08 -0400
Subject: [PATCH 1/2] Revert "[PowerPC][AIX] xfail atan-intrinsic to unblock
bot (#143723)"
This reverts commit adfea33f0c412b8475b755a8d82c9961b785eb02.
---
llvm/test/Transforms/InstSimplify/ConstProp/atan-intrinsic.ll | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/atan-intrinsic.ll b/llvm/test/Transforms/InstSimplify/ConstProp/atan-intrinsic.ll
index c5c17d65524c2..d824d6d35643d 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/atan-intrinsic.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/atan-intrinsic.ll
@@ -1,6 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
-; XFAIL: target={{.*}}-aix{{.*}}
define double @test_atan_0() {
; CHECK-LABEL: define double @test_atan_0() {
>From 139bf5bff27588f812f165c05a086581beb29dec Mon Sep 17 00:00:00 2001
From: Lei Huang <lei at ca.ibm.com>
Date: Thu, 12 Jun 2025 12:08:31 -0400
Subject: [PATCH 2/2] [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
---
llvm/lib/Analysis/ConstantFolding.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 139a0b81e299b..6a54c7355d70a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2549,6 +2549,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
case Intrinsic::cosh:
return ConstantFoldFP(cosh, APF, Ty);
case Intrinsic::atan:
+ // Implement optional behavior from C's Annex F for +/-0.0.
+ if (U.isZero())
+ return ConstantFP::get(Ty->getContext(), U);
return ConstantFoldFP(atan, APF, Ty);
case Intrinsic::sqrt:
return ConstantFoldFP(sqrt, APF, Ty);
More information about the llvm-commits
mailing list