re PR rtl-optimization/81290 (ICE in update_br_prob_note)
authorJan Hubicka <hubicka@ucw.cz>
Mon, 3 Jul 2017 14:40:46 +0000 (16:40 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Mon, 3 Jul 2017 14:40:46 +0000 (14:40 +0000)
PR middle-end/81290
* predict.c (force_edge_cold): Be more careful about propagation
backward.
* profile-count.h (profile_probability::guessed,
profile_probability::fdo, profile_count::guessed, profile_count::fdo):
New.
* tree-ssa-threadupdate.c (recompute_probabilities): Result is guessed.

* gcc.c-torture/compile/pr81290.c: New.

From-SVN: r249924

gcc/ChangeLog
gcc/predict.c
gcc/profile-count.h
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr81290.c [new file with mode: 0644]
gcc/tree-ssa-threadupdate.c

index 945708bf20c4058deb9da60f30e202c4b2396811..8d2a79a92e1a96f5c89e7dec4c61074e112a5ed5 100644 (file)
@@ -1,3 +1,13 @@
+2017-07-02  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR middle-end/81290
+       * predict.c (force_edge_cold): Be more careful about propagation
+       backward.
+       * profile-count.h (profile_probability::guessed,
+       profile_probability::fdo, profile_count::guessed, profile_count::fdo):
+       New.
+       * tree-ssa-threadupdate.c (recompute_probabilities): Result is guessed.
+
 2017-07-03  James Greenhalgh  <james.greenhalgh@arm.com>
 
        * doc/invoke.texi (rcpc architecture extension): Document it.
index 4d01bf357efd4eb6ae971601144ce9337b32c63d..2a7dbfa4d9bda2f160322eb5654171cb0febf3ba 100644 (file)
@@ -3962,15 +3962,26 @@ force_edge_cold (edge e, bool impossible)
              e2->count.apply_scale (count_sum2, count_sum);
            e2->probability /= prob_comp;
          }
-      if (current_ir_type () != IR_GIMPLE)
+      if (current_ir_type () != IR_GIMPLE
+         && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
        update_br_prob_note (e->src);
     }
   /* If all edges out of e->src are unlikely, the basic block itself
      is unlikely.  */
   else
     {
-      e->probability = profile_probability::always ();
-      if (current_ir_type () != IR_GIMPLE)
+      if (prob_sum == profile_probability::never ())
+        e->probability = profile_probability::always ();
+      else
+       {
+         if (impossible)
+           e->probability = profile_probability::never ();
+         /* If BB has some edges out that are not impossible, we can not
+            assume that BB itself is.  */
+         impossible = false;
+       }
+      if (current_ir_type () != IR_GIMPLE
+         && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
        update_br_prob_note (e->src);
       if (e->src->count == profile_count::zero ())
        return;
index e63b964413a9215e0f4adc0e47c96b6c090100c5..aef9da3bfce9f24ce0df30ee37922fafaca96579 100644 (file)
@@ -351,6 +351,22 @@ public:
       return profile_probability::always() - *this;
     }
 
+  /* Return THIS with quality dropped to GUESSED.  */
+  profile_probability guessed () const
+    {
+      profile_probability ret = *this;
+      ret.m_quality = profile_guessed;
+      return ret;
+    }
+
+  /* Return THIS with quality dropped to AFDO.  */
+  profile_probability afdo () const
+    {
+      profile_probability ret = *this;
+      ret.m_quality = profile_afdo;
+      return ret;
+    }
+
   profile_probability combine_with_freq (int freq1, profile_probability other,
                                         int freq2) const
     {
@@ -767,6 +783,22 @@ public:
       return ret;
     }
 
+  /* Return THIS with quality dropped to GUESSED.  */
+  profile_count guessed () const
+    {
+      profile_count ret = *this;
+      ret.m_quality = profile_guessed;
+      return ret;
+    }
+
+  /* Return THIS with quality dropped to AFDO.  */
+  profile_count afdo () const
+    {
+      profile_count ret = *this;
+      ret.m_quality = profile_afdo;
+      return ret;
+    }
+
   /* Return probability of event with counter THIS within event with counter
      OVERALL.  */
   profile_probability probability_in (const profile_count overall) const
index 6158e3719b323562fc996bd55920501569559288..313a939820bc70823b922ad3fa2d9e880116833e 100644 (file)
@@ -1,3 +1,8 @@
+2017-07-02  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR middle-end/81290
+       * gcc.c-torture/compile/pr81290.c: New.
+
 2017-07-03  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/60510
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr81290.c b/gcc/testsuite/gcc.c-torture/compile/pr81290.c
new file mode 100644 (file)
index 0000000..1fd8b20
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-options "-funroll-loops -w" } */
+int vz;
+
+void
+ms (int sw, int cm)
+{
+  for (vz = 0; vz < 19; ++vz)
+    {
+ fx:
+      sw *= 2;
+    }
+
+  for (;;)
+    {
+      if (sw != 0)
+        for (;;)
+          {
+          }
+      if (1 / 0 && cm != 0)
+        goto fx;
+    }
+}
index f5bc95f092f749ccf930f4e786fad9eb8a6b09c1..235a907339970cd80092428e8aebdbb7dba37c68 100644 (file)
@@ -908,7 +908,7 @@ recompute_probabilities (basic_block bb)
 
       /* Prevent overflow computation due to insane profiles.  */
       if (esucc->count < bb->count)
-       esucc->probability = esucc->count.probability_in (bb->count);
+       esucc->probability = esucc->count.probability_in (bb->count).guessed ();
       else
        /* Can happen with missing/guessed probabilities, since we
           may determine that more is flowing along duplicated
@@ -1051,7 +1051,8 @@ freqs_to_counts_path (struct redirection_data *rd)
       if (ein->probability.initialized_p ())
         ein->count = profile_count::from_gcov_type
                  (apply_probability (ein->src->frequency * REG_BR_PROB_BASE,
-                                       ein->probability.to_reg_br_prob_base ()));
+                                       ein->probability
+                                         .to_reg_br_prob_base ())).guessed ();
       else
        /* FIXME: this is hack; we should track uninitialized values.  */
        ein->count = profile_count::zero ();