[PATCH] Fix PR89664

Richard Biener rguenther@suse.de
Mon Mar 11 19:54:00 GMT 2019


Bootstrap & regtest in progress on x86_64-unknown-linux-gnu.

Richard.

2019-03-11  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.

Index: gcc/tree-ssa-math-opts.c
===================================================================
--- gcc/tree-ssa-math-opts.c	(revision 269212)
+++ gcc/tree-ssa-math-opts.c	(working copy)
@@ -799,7 +799,7 @@ execute_cse_reciprocals_1 (gimple_stmt_i
 
   /* 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_i
 	}
     }
 
+out:
   for (occ = occ_head; occ; )
     occ = free_bb (occ);
 
Index: gcc/testsuite/gfortran.dg/pr89664.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr89664.f90	(nonexistent)
+++ gcc/testsuite/gfortran.dg/pr89664.f90	(working copy)
@@ -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



More information about the Gcc-patches mailing list