[llvm] 2981a94 - [EarlyCSE][ConstantFolding] do not constant fold atan2(+/-0.0, +/-0.0), part 2
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 20 07:18:03 PDT 2022
Author: Sanjay Patel
Date: 2022-08-20T10:16:06-04:00
New Revision: 2981a9490277a7920936d287c9703f0f7edef84b
URL: https://github.com/llvm/llvm-project/commit/2981a9490277a7920936d287c9703f0f7edef84b
DIFF: https://github.com/llvm/llvm-project/commit/2981a9490277a7920936d287c9703f0f7edef84b.diff
LOG: [EarlyCSE][ConstantFolding] do not constant fold atan2(+/-0.0, +/-0.0), part 2
Follow-up to 7f1262a322c0d80f3. That patch avoided removing the
call, but it still allowed the constant-folded result. This
makes the behavior consistent with 1-arg libm folding: if the
call potentially raises an exception, then we just bail out.
It seems likely that there are other corner-cases like this,
but the tests are incomplete, so we have lived with these
discrepancies for a long time. This was untested before the
the constant folding was expanded in D127964.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/test/Transforms/EarlyCSE/atan.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 8ed291778da62..9187d49ca7a5a 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2569,6 +2569,11 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
break;
case LibFunc_atan2:
case LibFunc_atan2f:
+ // atan2(+/-0.0, +/-0.0) is known to raise an exception on some libm
+ // (Solaris), so we do not assume a known result for that.
+ if (Op1V.isZero() && Op2V.isZero())
+ return nullptr;
+ [[fallthrough]];
case LibFunc_atan2_finite:
case LibFunc_atan2f_finite:
if (TLI->has(Func))
diff --git a/llvm/test/Transforms/EarlyCSE/atan.ll b/llvm/test/Transforms/EarlyCSE/atan.ll
index adb6ff7f5c03e..e665e0c9e54d9 100644
--- a/llvm/test/Transforms/EarlyCSE/atan.ll
+++ b/llvm/test/Transforms/EarlyCSE/atan.ll
@@ -55,7 +55,7 @@ define x86_fp80 @atanl_x86(x86_fp80 %x) {
define float @callatan2_00() {
; CHECK-LABEL: @callatan2_00(
; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float 0.000000e+00, float 0.000000e+00)
-; CHECK-NEXT: ret float 0.000000e+00
+; CHECK-NEXT: ret float [[CALL]]
;
%call = call float @atan2f(float 0.0, float 0.0)
ret float %call
@@ -66,7 +66,7 @@ define float @callatan2_00() {
define float @callatan2_n00() {
; CHECK-LABEL: @callatan2_n00(
; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float -0.000000e+00, float 0.000000e+00)
-; CHECK-NEXT: ret float -0.000000e+00
+; CHECK-NEXT: ret float [[CALL]]
;
%call = call float @atan2f(float -0.0, float 0.0)
ret float %call
@@ -77,7 +77,7 @@ define float @callatan2_n00() {
define float @callatan2_0n0() {
; CHECK-LABEL: @callatan2_0n0(
; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float 0.000000e+00, float -0.000000e+00)
-; CHECK-NEXT: ret float 0x400921FB60000000
+; CHECK-NEXT: ret float [[CALL]]
;
%call = call float @atan2f(float 0.0, float -0.0)
ret float %call
@@ -88,7 +88,7 @@ define float @callatan2_0n0() {
define float @callatan2_n0n0() {
; CHECK-LABEL: @callatan2_n0n0(
; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float -0.000000e+00, float -0.000000e+00)
-; CHECK-NEXT: ret float 0xC00921FB60000000
+; CHECK-NEXT: ret float [[CALL]]
;
%call = call float @atan2f(float -0.0, float -0.0)
ret float %call
More information about the llvm-commits
mailing list