Skip to content

Commit c87de4c

Browse files
[ConstantFold] Special case log1p +/-0.0
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 e241093 commit c87de4c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 3 additions & 0 deletions
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;

0 commit comments

Comments
 (0)