re PR tree-optimization/89664 (ICE in free_bb, at tree-ssa-math-opts.c:522)
authorRichard Biener <rguenther@suse.de>
Tue, 12 Mar 2019 07:56:23 +0000 (07:56 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 12 Mar 2019 07:56:23 +0000 (07:56 +0000)
2019-03-12  Richard Biener  <rguenther@suse.de>

PR tree-optimization/89664
* tree-ssa-math-opts.c (execute_cse_reciprocals_1): Properly
free the occurance tree after the early out.

* gfortran.dg/pr89664.f90: New testcase.

From-SVN: r269604

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr89664.f90 [new file with mode: 0644]
gcc/tree-ssa-math-opts.c

index 64bf6017d16fb17faeb01f331b3db42b020351be..85d11c95dd4f2fa5755bb8242064008e6378bf1a 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/89664
+       * tree-ssa-math-opts.c (execute_cse_reciprocals_1): Properly
+       free the occurance tree after the early out.
+
 2019-03-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR middle-end/89655
index 8c992a8ed421bebf6a51aea5299b8571d6d74c95..c4f79ae72547065bd94447e8d417310cad8fa01c 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-12  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/89664
+       * gfortran.dg/pr89664.f90: New testcase.
+
 2019-03-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR fortran/89651
diff --git a/gcc/testsuite/gfortran.dg/pr89664.f90 b/gcc/testsuite/gfortran.dg/pr89664.f90
new file mode 100644 (file)
index 0000000..5557806
--- /dev/null
@@ -0,0 +1,24 @@
+! { dg-do compile }
+! { dg-options "-Ofast" }
+
+subroutine s (x)
+   real :: x
+   call sub (x)
+end
+subroutine sub (x)
+   real :: x, y
+   logical :: a, b
+   real :: f1, f2, f3, f4
+   y = f1()
+   a = .false.
+   if ( f2() > f3() ) a = .true.
+   b = .false.
+   if ( f2() > f4() ) b = .true.
+   if ( a ) then
+      x = 1.0
+   else if ( b ) then
+      x = 1.0/y**2
+   else
+      x = 1.0/y - y**2
+   end if
+end
index 5f1b3690239bebc243d0315040f04011a8c8eaac..cb8a9143833a5c8c7ad2255678a5c8234cda5ce9 100644 (file)
@@ -799,7 +799,7 @@ execute_cse_reciprocals_1 (gimple_stmt_iterator *def_gsi, tree def)
 
   /* If it is more profitable to optimize 1 / x, don't optimize 1 / (x * x).  */
   if (sqrt_recip_count > square_recip_count)
-    return;
+    goto out;
 
   /* Do the expensive part only if we can hope to optimize something.  */
   if (count + square_recip_count >= threshold && count >= 1)
@@ -842,6 +842,7 @@ execute_cse_reciprocals_1 (gimple_stmt_iterator *def_gsi, tree def)
        }
     }
 
+out:
   for (occ = occ_head; occ; )
     occ = free_bb (occ);