Skip to content

Commit 5091a35

Browse files
[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.
1 parent 6f10b65 commit 5091a35

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
24072407
break;
24082408
case LibFunc_log1p:
24092409
case LibFunc_log1pf:
2410+
// Implement optional behavior from C's Annex F for +/-0.0.
2411+
if (U.isZero())
2412+
return ConstantFP::get(Ty->getContext(), U);
24102413
if (APF > APFloat::getOne(APF.getSemantics(), true) && TLI->has(Func))
24112414
return ConstantFoldFP(log1p, APF, Ty);
24122415
break;

llvm/test/Transforms/InstCombine/log1p.ll

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
; XFAIL: target={{.*}}-aix{{.*}}
21
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
32
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
43

0 commit comments

Comments
 (0)