[llvm-branch-commits] [llvm-branch] r371381 - Merging r371221 and r371224:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Sep 9 02:43:19 PDT 2019
Author: hans
Date: Mon Sep 9 02:43:19 2019
New Revision: 371381
URL: http://llvm.org/viewvc/llvm-project?rev=371381&view=rev
Log:
Merging r371221 and r371224:
------------------------------------------------------------------------
r371221 | spatel | 2019-09-06 18:10:18 +0200 (Fri, 06 Sep 2019) | 3 lines
[SimplifyLibCalls] handle pow(x,-0.0) before it can assert (PR43233)
https://bugs.llvm.org/show_bug.cgi?id=43233
------------------------------------------------------------------------
------------------------------------------------------------------------
r371224 | jfb | 2019-09-06 18:26:59 +0200 (Fri, 06 Sep 2019) | 39 lines
[InstCombine] pow(x, +/- 0.0) -> 1.0
Summary:
This isn't an important optimization at all... We're already doing:
pow(x, 0.0) -> 1.0
My patch merely teaches instcombine that -0.0 does the same.
However, doing this fixes an AMAZING bug! Compile this program:
extern "C" double pow(double, double);
double boom(double base) {
return pow(base, -0.0);
}
With:
clang++ ~/Desktop/fast-math.cpp -ffast-math -O2 -S
And clang will crash with a signal. Wow, fast math is so fast it ICEs the
compiler! Arguably, the generated math is infinitely fast.
What's actually happening is that we recurse infinitely in getPow. In debug we
hit its assertion:
assert(Exp != 0 && "Incorrect exponent 0 not handled");
We avoid this entire mess if we instead recognize that an exponent of positive
and negative zero yield 1.0.
A separate commit, r371221, fixed the same problem. This only contains the added
tests.
<rdar://problem/54598300>
Reviewers: scanon
Subscribers: hiraditya, jkorous, dexonsmith, ributzka, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67248
------------------------------------------------------------------------
Added:
llvm/branches/release_90/test/Transforms/InstCombine/pow-0.ll
- copied unchanged from r371224, llvm/trunk/test/Transforms/InstCombine/pow-0.ll
Modified:
llvm/branches/release_90/ (props changed)
llvm/branches/release_90/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/branches/release_90/test/Transforms/InstCombine/pow-4.ll
Propchange: llvm/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 9 02:43:19 2019
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,366431,366447,366481,366487,366527,366570,366660,366868,366925,367019,367030,367062,367084,367124,367215,367292,367304,367306,367314,367340-367341,367394,367396,367398,367403,367412,367417,367429,367580,367662,367750,367753,367846-367847,367898,367941,368004,368164,368230,368300,368315,368324,368477-368478,368517-368519,368554,368572,368873,369011,369026,369084,369095,369097,369168,369199,369310,369426,369443,369886,370036,370176,370204,370271,370355,370404,370426,370430,370720-370721,370753,371048,371088,371095,371111,371262,371305,371307
+/llvm/trunk:155241,366431,366447,366481,366487,366527,366570,366660,366868,366925,367019,367030,367062,367084,367124,367215,367292,367304,367306,367314,367340-367341,367394,367396,367398,367403,367412,367417,367429,367580,367662,367750,367753,367846-367847,367898,367941,368004,368164,368230,368300,368315,368324,368477-368478,368517-368519,368554,368572,368873,369011,369026,369084,369095,369097,369168,369199,369310,369426,369443,369886,370036,370176,370204,370271,370355,370404,370426,370430,370720-370721,370753,371048,371088,371095,371111,371221,371224,371262,371305,371307
Modified: llvm/branches/release_90/lib/Transforms/Utils/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/lib/Transforms/Utils/SimplifyLibCalls.cpp?rev=371381&r1=371380&r2=371381&view=diff
==============================================================================
--- llvm/branches/release_90/lib/Transforms/Utils/SimplifyLibCalls.cpp (original)
+++ llvm/branches/release_90/lib/Transforms/Utils/SimplifyLibCalls.cpp Mon Sep 9 02:43:19 2019
@@ -1480,8 +1480,8 @@ Value *LibCallSimplifier::optimizePow(Ca
if (match(Expo, m_SpecificFP(-1.0)))
return B.CreateFDiv(ConstantFP::get(Ty, 1.0), Base, "reciprocal");
- // pow(x, 0.0) -> 1.0
- if (match(Expo, m_SpecificFP(0.0)))
+ // pow(x, +/-0.0) -> 1.0
+ if (match(Expo, m_AnyZeroFP()))
return ConstantFP::get(Ty, 1.0);
// pow(x, 1.0) -> x
Modified: llvm/branches/release_90/test/Transforms/InstCombine/pow-4.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_90/test/Transforms/InstCombine/pow-4.ll?rev=371381&r1=371380&r2=371381&view=diff
==============================================================================
--- llvm/branches/release_90/test/Transforms/InstCombine/pow-4.ll (original)
+++ llvm/branches/release_90/test/Transforms/InstCombine/pow-4.ll Mon Sep 9 02:43:19 2019
@@ -223,3 +223,13 @@ define <4 x float> @test_simplify_3_5(<4
ret <4 x float> %1
}
+; Make sure that -0.0 exponent is always simplified.
+
+define double @PR43233(double %x) {
+; CHECK-LABEL: @PR43233(
+; CHECK-NEXT: ret double 1.000000e+00
+;
+ %r = call fast double @llvm.pow.f64(double %x, double -0.0)
+ ret double %r
+}
+
More information about the llvm-branch-commits
mailing list