[llvm] 5091a35 - [ConstantFold] Special case log1p +/-0.0 (#114635)

via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 2 17:06:43 PDT 2024


Author: Hubert Tong
Date: 2024-11-02T20:06:39-04:00
New Revision: 5091a359d9807db8f7d62375696f93fc34226969

URL: https://github.com/llvm/llvm-project/commit/5091a359d9807db8f7d62375696f93fc34226969
DIFF: https://github.com/llvm/llvm-project/commit/5091a359d9807db8f7d62375696f93fc34226969.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Analysis/ConstantFolding.cpp
    llvm/test/Transforms/InstCombine/log1p.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index c5a2c2f52f8dc2..88db315ffd0bcb 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;

diff  --git a/llvm/test/Transforms/InstCombine/log1p.ll b/llvm/test/Transforms/InstCombine/log1p.ll
index bbf89db8c34105..81d3cc8a4f7ac9 100644
--- a/llvm/test/Transforms/InstCombine/log1p.ll
+++ b/llvm/test/Transforms/InstCombine/log1p.ll
@@ -1,4 +1,3 @@
-; XFAIL: target={{.*}}-aix{{.*}}
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
 


        


More information about the llvm-commits mailing list