[SimplifyLibCalls] handle pow(x,-0.0) before it can assert (PR43233)
authorSanjay Patel <spatel@rotateright.com>
Fri, 6 Sep 2019 16:10:18 +0000 (16:10 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 6 Sep 2019 16:10:18 +0000 (16:10 +0000)
https://bugs.llvm.org/show_bug.cgi?id=43233

llvm-svn: 371221

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/test/Transforms/InstCombine/pow-4.ll

index 1f397c0..7a13cff 100644 (file)
@@ -1562,8 +1562,8 @@ Value *LibCallSimplifier::optimizePow(CallInst *Pow, IRBuilder<> &B) {
   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
index e435239..4aac27f 100644 (file)
@@ -223,3 +223,13 @@ define <4 x float> @test_simplify_3_5(<4 x float> %x) {
   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
+}
+