Skip to content

Commit 0a64bc5

Browse files
committed
add test and handling for atan lib calls
1 parent 139bf5b commit 0a64bc5

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
26052605
break;
26062606
case LibFunc_atan:
26072607
case LibFunc_atanf:
2608+
// Implement optional behavior from C's Annex F for +/-0.0.
2609+
if (U.isZero())
2610+
return ConstantFP::get(Ty->getContext(), U);
26082611
if (TLI->has(Func))
26092612
return ConstantFoldFP(atan, APF, Ty);
26102613
break;

llvm/test/Transforms/InstSimplify/ConstProp/calls.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,17 @@ entry:
202202
ret float %0
203203
}
204204

205+
define float @test_atan_negzero() nounwind uwtable ssp {
206+
entry:
207+
; CHECK-LABEL: @test_atan_negzero(
208+
; CHECK: ret float -0.000000e+00
209+
;
210+
; FNOBUILTIN-LABEL: @test_atan_negzero(
211+
; FNOBUILTIN: ret float -0.000000e+00
212+
;
213+
%1 = call float @atanf(float -0.0)
214+
ret float %1
215+
}
216+
205217
declare double @llvm.pow.f64(double, double) nounwind readonly
206218
declare float @llvm.pow.f32(float, float) nounwind readonly

0 commit comments

Comments
 (0)