[llvm] [ConstantFold] Special case atan +/-0.0 (PR #143962)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 18 17:07:21 PDT 2025
================
@@ -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.
----------------
topperc wrote:
```
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/calls.ll b/llvm/test/Transforms/InstSimplify/ConstProp/calls.ll
index 61a30c781c0f..f4320dc518aa 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/calls.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/calls.ll
@@ -204,3 +204,15 @@ entry:
declare double @llvm.pow.f64(double, double) nounwind readonly
declare float @llvm.pow.f32(float, float) nounwind readonly
+
+define float @test_atan_negzero() {
+; CHECK-LABEL: define float @test_atan_negzero() {
+; CHECK-NEXT: ret float -0.000000e+00
+;
+; FNOBUILTIN-LABEL: define float @test_atan_negzero() {
+; FNOBUILTIN-NEXT: [[TMP1:%.*]] = call float @atanf(float -0.000000e+00)
+; FNOBUILTIN-NEXT: ret float [[TMP1]]
+;
+ %1 = call float @atanf(float -0.0)
+ ret float %1
+}
```
https://github.com/llvm/llvm-project/pull/143962
More information about the llvm-commits
mailing list