diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 8ed291778da62..9187d49ca7a5a 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -2569,6 +2569,11 @@ static Constant *ConstantFoldScalarCall2(StringRef Name, break; case LibFunc_atan2: case LibFunc_atan2f: + // atan2(+/-0.0, +/-0.0) is known to raise an exception on some libm + // (Solaris), so we do not assume a known result for that. + if (Op1V.isZero() && Op2V.isZero()) + return nullptr; + [[fallthrough]]; case LibFunc_atan2_finite: case LibFunc_atan2f_finite: if (TLI->has(Func)) diff --git a/llvm/test/Transforms/EarlyCSE/atan.ll b/llvm/test/Transforms/EarlyCSE/atan.ll index adb6ff7f5c03e..e665e0c9e54d9 100644 --- a/llvm/test/Transforms/EarlyCSE/atan.ll +++ b/llvm/test/Transforms/EarlyCSE/atan.ll @@ -55,7 +55,7 @@ define x86_fp80 @atanl_x86(x86_fp80 %x) { define float @callatan2_00() { ; CHECK-LABEL: @callatan2_00( ; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float 0.000000e+00, float 0.000000e+00) -; CHECK-NEXT: ret float 0.000000e+00 +; CHECK-NEXT: ret float [[CALL]] ; %call = call float @atan2f(float 0.0, float 0.0) ret float %call @@ -66,7 +66,7 @@ define float @callatan2_00() { define float @callatan2_n00() { ; CHECK-LABEL: @callatan2_n00( ; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float -0.000000e+00, float 0.000000e+00) -; CHECK-NEXT: ret float -0.000000e+00 +; CHECK-NEXT: ret float [[CALL]] ; %call = call float @atan2f(float -0.0, float 0.0) ret float %call @@ -77,7 +77,7 @@ define float @callatan2_n00() { define float @callatan2_0n0() { ; CHECK-LABEL: @callatan2_0n0( ; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float 0.000000e+00, float -0.000000e+00) -; CHECK-NEXT: ret float 0x400921FB60000000 +; CHECK-NEXT: ret float [[CALL]] ; %call = call float @atan2f(float 0.0, float -0.0) ret float %call @@ -88,7 +88,7 @@ define float @callatan2_0n0() { define float @callatan2_n0n0() { ; CHECK-LABEL: @callatan2_n0n0( ; CHECK-NEXT: [[CALL:%.*]] = call float @atan2f(float -0.000000e+00, float -0.000000e+00) -; CHECK-NEXT: ret float 0xC00921FB60000000 +; CHECK-NEXT: ret float [[CALL]] ; %call = call float @atan2f(float -0.0, float -0.0) ret float %call