[llvm] 7f1262a - [EarlyCSE][ConstantFolding] do not constant fold atan2(+/-0.0, +/-0.0)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 09:31:13 PDT 2022
Author: Sanjay Patel
Date: 2022-08-19T12:27:29-04:00
New Revision: 7f1262a322c0d80f34964004dbd3ebec58404a5f
URL: https://github.com/llvm/llvm-project/commit/7f1262a322c0d80f34964004dbd3ebec58404a5f
DIFF: https://github.com/llvm/llvm-project/commit/7f1262a322c0d80f34964004dbd3ebec58404a5f.diff
LOG: [EarlyCSE][ConstantFolding] do not constant fold atan2(+/-0.0, +/-0.0)
These may raise an error (set errno) as discussed in the post-commit
comments for D127964, so we can't fold away the call and potentially
alter that behavior.
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 5194d85ee1e4..8ed291778da6 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -3371,10 +3371,11 @@ bool llvm::isMathLibCallNoop(const CallBase *Call,
case LibFunc_atan2:
case LibFunc_atan2f:
case LibFunc_atan2l:
- // POSIX, GLIBC and MSVC dictate atan2(0,0) is 0 and no error is raised.
- // C11 says that a domain error may optionally occur.
- // This is consistent with both.
- return true;
+ // Although IEEE-754 says atan2(+/-0.0, +/-0.0) are well-defined, and
+ // GLIBC and MSVC do not appear to raise an error on those, we
+ // cannot rely on that behavior. POSIX and C11 say that a domain error
+ // may occur, so allow for that possibility.
+ return !Op0.isZero() || !Op1.isZero();
default:
break;
diff --git a/llvm/test/Transforms/EarlyCSE/atan.ll b/llvm/test/Transforms/EarlyCSE/atan.ll
index 11dce636fbbb..adb6ff7f5c03 100644
--- a/llvm/test/Transforms/EarlyCSE/atan.ll
+++ b/llvm/test/Transforms/EarlyCSE/atan.ll
@@ -50,32 +50,44 @@ define x86_fp80 @atanl_x86(x86_fp80 %x) {
ret x86_fp80 %call
}
+; This is not folded because it is known to set errno on some systems.
+
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
;
%call = call float @atan2f(float 0.0, float 0.0)
ret float %call
}
+; This is not folded because it is known to set errno on some systems.
+
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
;
%call = call float @atan2f(float -0.0, float 0.0)
ret float %call
}
+; This is not folded because it is known to set errno on some systems.
+
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
;
%call = call float @atan2f(float 0.0, float -0.0)
ret float %call
}
+; This is not folded because it is known to set errno on some systems.
+
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
;
%call = call float @atan2f(float -0.0, float -0.0)
More information about the llvm-commits
mailing list