Hi.

Following patch moves a probability calculation to a place where
it's really used. Otherwise one can end up with division by zero
that can't happen as there's no edge for which the probability
would be used.

Patch survives tests on x86_64-linux-gnu and bootstrap fine.

Ready for trunk?
Thanks,
Martin

gcc/ChangeLog:

2019-01-02  Martin Liska  <mli...@suse.cz>

        PR tree-optimization/88650
        * predict.c (set_even_probabilities): Calculate probability
        remainer only when really used.

gcc/testsuite/ChangeLog:

2019-01-02  Martin Liska  <mli...@suse.cz>

        PR tree-optimization/88650
        * gfortran.dg/predict-3.f90: New test.
---
 gcc/predict.c                           | 16 +++++++-------
 gcc/testsuite/gfortran.dg/predict-3.f90 | 28 +++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 7 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/predict-3.f90


diff --git a/gcc/predict.c b/gcc/predict.c
index 745be185a29..0ac8adf286f 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -877,19 +877,21 @@ set_even_probabilities (basic_block bb,
 	    int p = prediction->ep_probability;
 	    profile_probability prob
 	      = profile_probability::from_reg_br_prob_base (p);
-	    profile_probability remainder = prob.invert ();
-	    remainder -= profile_probability::very_unlikely ()
-	      .apply_scale (unlikely_count, 1);
-	    int count = nedges - unlikely_count - 1;
-	    gcc_assert (count >= 0);
-	    profile_probability even = remainder.apply_scale (1, count);
 
 	    if (prediction->ep_edge == e)
 	      e->probability = prob;
 	    else if (unlikely_edges != NULL && unlikely_edges->contains (e))
 	      e->probability = profile_probability::very_unlikely ();
 	    else
-	      e->probability = even;
+	      {
+		profile_probability remainder = prob.invert ();
+		remainder -= profile_probability::very_unlikely ()
+		  .apply_scale (unlikely_count, 1);
+		int count = nedges - unlikely_count - 1;
+		gcc_assert (count >= 0);
+
+		e->probability = remainder.apply_scale (1, count);
+	      }
 	  }
 	else
 	  e->probability = profile_probability::never ();
diff --git a/gcc/testsuite/gfortran.dg/predict-3.f90 b/gcc/testsuite/gfortran.dg/predict-3.f90
new file mode 100644
index 00000000000..f5437883f9d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/predict-3.f90
@@ -0,0 +1,28 @@
+! { dg-do compile }
+! { dg-options "-fno-tree-fre -fno-tree-ccp -Og" }
+
+program simplify_transfer
+  call pr30881 ()
+contains
+  subroutine pr18769 ()
+    type t
+    end type t
+  end subroutine pr18769
+  subroutine pr30881 ()
+    INTEGER, PARAMETER :: K=1
+    I=TRANSFER(.TRUE.,K)
+    SELECT CASE(I)
+      CASE(TRANSFER(.TRUE.,K))
+      CASE(TRANSFER(.FALSE.,K))
+        STOP 2
+      CASE DEFAULT
+        STOP 3
+    END SELECT
+  END subroutine pr30881
+  subroutine pr31194 ()
+  end subroutine pr31194
+  subroutine pr31216 ()
+  END subroutine pr31216
+  subroutine pr31427 ()
+  END subroutine pr31427
+end program simplify_transfer

Reply via email to