aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorHubert Tong <hubert.reinterpretcast@gmail.com>2024-11-02 20:06:39 -0400
committerGitHub <noreply@github.com>2024-11-02 20:06:39 -0400
commit5091a359d9807db8f7d62375696f93fc34226969 (patch)
tree9179d8902f57398e561f04801a8677567609f808 /llvm/lib/Analysis/ConstantFolding.cpp
parent6f10b65297707c1e964d570421ab4559dc2928d4 (diff)
downloadllvm-5091a359d9807db8f7d62375696f93fc34226969.zip
llvm-5091a359d9807db8f7d62375696f93fc34226969.tar.gz
llvm-5091a359d9807db8f7d62375696f93fc34226969.tar.bz2
[ConstantFold] Special case log1p +/-0.0 (#114635)
C's Annex F specifies that log1p +/-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.
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c5a2c2f..88db315 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -2407,6 +2407,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
break;
case LibFunc_log1p:
case LibFunc_log1pf:
+ // Implement optional behavior from C's Annex F for +/-0.0.
+ if (U.isZero())
+ return ConstantFP::get(Ty->getContext(), U);
if (APF > APFloat::getOne(APF.getSemantics(), true) && TLI->has(Func))
return ConstantFoldFP(log1p, APF, Ty);
break;