tree-ssa-ifcombine.c (update_profile_after_ifcombine): New function.
authorJan Hubicka <hubicka@ucw.cz>
Fri, 3 Feb 2017 14:03:35 +0000 (15:03 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Fri, 3 Feb 2017 14:03:35 +0000 (14:03 +0000)
* tree-ssa-ifcombine.c (update_profile_after_ifcombine): New function.
(ifcombine_ifandif): Use it.
* gcc.dg/tree-ssa/ssa-ifcombine-1.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-2.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-3.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-4.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-5.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-6.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-7.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-8.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-9.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-10.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-11.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-12.c: Check for no profile mismatches.
* gcc.dg/tree-ssa/ssa-ifcombine-13.c: Check for no profile mismatches.

From-SVN: r245151

16 files changed:
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-1.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-10.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-11.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-12.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-2.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-3.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-4.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-5.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-6.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-7.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-8.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-9.c
gcc/tree-ssa-ifcombine.c

index 445f27b5e0e81532af16e9efb75be0a1882cd226..7fd658ef9998b6a39e4824325695d5f0c3965bb6 100644 (file)
@@ -1,3 +1,8 @@
+2017-02-02  Jan Hubicka  <hubicka@ucw.cz>
+
+       * tree-ssa-ifcombine.c (update_profile_after_ifcombine): New function.
+       (ifcombine_ifandif): Use it.
+
 2017-02-03  Martin Liska  <mliska@suse.cz>
 
        * doc/invoke.texi: Document default value for
index 1289892dadaf4da122ab9b9811c02877b9ce6d79..ddcc87e86eb19f4cd4bdaea139c8b6fe72b3b12a 100644 (file)
@@ -1,3 +1,19 @@
+2017-02-02  Jan Hubicka  <hubicka@ucw.cz>
+
+       * gcc.dg/tree-ssa/ssa-ifcombine-1.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-2.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-3.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-4.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-5.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-6.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-7.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-8.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-9.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-10.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-11.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-12.c: Check for no profile mismatches.
+       * gcc.dg/tree-ssa/ssa-ifcombine-13.c: Check for no profile mismatches.
+
 2017-02-02  Martin Sebor  <msebor@redhat.com>
 
        PR middle-end/79275
index edbe287d1db04fa9a3cc135bcd5a899242862ef0..e38c1113de58e6087d7188031a08daa3057bd911 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase for PR31657.  */
 
@@ -14,3 +14,4 @@ int foo (int x, int a, int b)
 }
 
 /* { dg-final { scan-tree-dump "\\|" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index 94221d0983f2d2faa1066d56de37cbb2f5be1b0d..1948af82896e37bdb5c937ce393773ef09c1cb2e 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase for PR31657.  */
 
@@ -17,3 +17,4 @@ int f(int x, int a, int b)
   return t;
 }
 /* { dg-final { scan-tree-dump "& 5" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index d192911c4ff0be79c429d142266acbd119e24f9d..780ecf57b3aefd12a9f13180860b67bbed1a4d92 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase for PR31657.  */
 int g(void);
@@ -18,3 +18,4 @@ int f(int x, int a, int b)
 }
 
 /* { dg-final { scan-tree-dump "& 5" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index 88502c3278b822673a6392301b91004977778aa3..72ffaf503fa161814dbacd19fe78c0a9dc1edfff 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-vrp -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fno-tree-vrp -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase for PR31657.  */
 
@@ -17,3 +17,4 @@ int f(int x, int a, int b)
   return t;
 }
 /* { dg-final { scan-tree-dump "& 5" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index bbafe7b82db41944555f28339efad2bc29ba730e..7f4f011faeea8c6ec64fd862972cf4f5161ae265 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized" } */
+/* { dg-options "-O1 -fdump-tree-optimized-details-blocks" } */
 /* { dg-additional-options "-mbranch-cost=2" { target { i?86-*-* x86_64-*-* s390*-*-* avr*-*-* } } } */
 
 _Bool f1(_Bool a, _Bool b)
@@ -18,3 +18,4 @@ _Bool f1(_Bool a, _Bool b)
 /* For LOGICAL_OP_NON_SHORT_CIRCUIT, this should be optimized
    into return a & b;, with no ifs.  */
 /* { dg-final { scan-tree-dump-not "if" "optimized" { target { i?86-*-* x86_64-*-* s390*-*-* avr*-*-* } } } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index c2a1a087c4442b3218e0de910d53dc78d7d8f7c0..ac70d4b639a7c8c0a443de3b74883b638191f053 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase for PR31657.  */
 
@@ -20,3 +20,4 @@ doit:
 }
 
 /* { dg-final { scan-tree-dump "\\|" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index ff543c17acbcb4c4ec14763e76285b3fcf14aebf..c51fdf3a9c4f583cf8f4fbe85af7d90ed947e13a 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase extracted from PR15353.  */
 
@@ -20,3 +20,4 @@ doit:
 }
 
 /* { dg-final { scan-tree-dump ">=" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index 83171940b1a3e5811843077b685cdf64ad18f572..178ebda47587ebf1efe5634971effbaf4f28a277 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase extracted from PR15353.  */
 
@@ -18,3 +18,4 @@ void foo (int x, int a)
 }
 
 /* { dg-final { scan-tree-dump "!=" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index d8349c1a5d7774d7b63721ebc9a328742271e9ca..c16a0d9a94bd6104e9a920baf96921d4182125b8 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-optimized" } */
+/* { dg-options "-O -fdump-tree-optimized-details-blocks" } */
 
 /* Testcase from PR15353.  */
 
@@ -17,3 +17,4 @@ int f(int *i, int *j)
 }
 
 /* { dg-final { scan-tree-dump ">=" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "optimized" } } */
index 55450abd2058b93e16d8b5edeefd546ad6200706..a85531d19ec1bb9c9fc30c5edd87474f2d931627 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-ifcombine" } */
+/* { dg-options "-O -fdump-tree-ifcombine-details-blocks" } */
 
 void bar (void);
 
@@ -34,3 +34,4 @@ foo2 (unsigned int a)
 
 /* { dg-final { scan-tree-dump "optimizing bits or bits test" "ifcombine" } } */
 /* { dg-final { scan-tree-dump "optimizing double bit test" "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "ifcombine" } } */
index 205309005445cc200b328a0b94d49a4a2903507e..7eab7fd463636f7bd3adf7e63a5946694de66439 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fdump-tree-ifcombine" } */
+/* { dg-options "-O -fdump-tree-ifcombine-details-blocks" } */
 
 int test1 (int i, int j)
 {
@@ -12,3 +12,4 @@ int test1 (int i, int j)
 /* The above should be optimized to a i > j test by ifcombine.  */
 
 /* { dg-final { scan-tree-dump " > " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "ifcombine" } } */
index c89d264d46501d0670287cc327c65ffa81177786..5bddf68e2d10426d43daaaa82046547c6d982996 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O -fno-trapping-math -fdump-tree-ifcombine" } */
+/* { dg-options "-O -fno-trapping-math -fdump-tree-ifcombine-details-blocks" } */
 
 double test1 (double i, double j)
 {
@@ -22,3 +22,4 @@ plouf:
    Instead we get u<=, which is acceptable with -fno-trapping-math.  */
 
 /* { dg-final { scan-tree-dump " u<= " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "ifcombine" } } */
index c4c55732e450448f6711380a2ed10e2ccca7196f..bb18e0f01b09877a2ec1204e2e87e5b7cb44b41e 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-trapping-math -fdump-tree-ifcombine" } */
+/* { dg-options "-O2 -fno-trapping-math -fdump-tree-ifcombine-details-blocks" } */
 
 void f ();
 enum Sign { NEG=-1, ZERO, POS };
@@ -19,3 +19,4 @@ void g (double x)
    The transformation would also be legal with -ftrapping-math.  */
 
 /* { dg-final { scan-tree-dump "optimizing.* < " "ifcombine" } } */
+/* { dg-final { scan-tree-dump-not "Invalid sum" "ifcombine" } } */
index 6e43b5c25a21c8db10fa0a9e03164f2feb51790f..16f6c73d7e6a092c5bb4d86a664ca6689ff587ea 100644 (file)
@@ -332,6 +332,51 @@ recognize_bits_test (gcond *cond, tree *name, tree *bits, bool inv)
   return true;
 }
 
+
+/* Update profile after code in outer_cond_bb was adjusted so
+   outer_cond_bb has no condition.  */
+
+static void
+update_profile_after_ifcombine (basic_block inner_cond_bb,
+                               basic_block outer_cond_bb)
+{
+  edge outer_to_inner = find_edge (outer_cond_bb, inner_cond_bb);
+  edge outer2 = (EDGE_SUCC (outer_cond_bb, 0) == outer_to_inner
+                ? EDGE_SUCC (outer_cond_bb, 1)
+                : EDGE_SUCC (outer_cond_bb, 0));
+  edge inner_taken = EDGE_SUCC (inner_cond_bb, 0);
+  edge inner_not_taken = EDGE_SUCC (inner_cond_bb, 1);
+  
+  if (inner_taken->dest != outer2->dest)
+    std::swap (inner_taken, inner_not_taken);
+  gcc_assert (inner_taken->dest == outer2->dest);
+
+  /* In the following we assume that inner_cond_bb has single predecessor.  */
+  gcc_assert (single_pred_p (inner_cond_bb));
+
+  /* Path outer_cond_bb->(outer2) needs to be merged into path
+     outer_cond_bb->(outer_to_inner)->inner_cond_bb->(inner_taken)
+     and probability of inner_not_taken updated.  */
+
+  outer_to_inner->count = outer_cond_bb->count;
+  inner_cond_bb->count = outer_cond_bb->count;
+  inner_taken->count += outer2->count;
+  outer2->count = 0;
+
+  inner_taken->probability = outer2->probability
+                            + RDIV (outer_to_inner->probability
+                                    * inner_taken->probability,
+                                    REG_BR_PROB_BASE);
+  if (inner_taken->probability > REG_BR_PROB_BASE)
+    inner_taken->probability = REG_BR_PROB_BASE;
+  inner_not_taken->probability = REG_BR_PROB_BASE
+                                - inner_taken->probability;
+
+  outer_to_inner->probability = REG_BR_PROB_BASE;
+  inner_cond_bb->frequency = outer_cond_bb->frequency;
+  outer2->probability = 0;
+}
+
 /* If-convert on a and pattern with a common else block.  The inner
    if is specified by its INNER_COND_BB, the outer by OUTER_COND_BB.
    inner_inv, outer_inv and result_inv indicate whether the conditions
@@ -394,6 +439,8 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
        outer_inv ? boolean_false_node : boolean_true_node);
       update_stmt (outer_cond);
 
+      update_profile_after_ifcombine (inner_cond_bb, outer_cond_bb);
+
       if (dump_file)
        {
          fprintf (dump_file, "optimizing double bit test to ");
@@ -471,6 +518,7 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
       gimple_cond_set_condition_from_tree (outer_cond,
        outer_inv ? boolean_false_node : boolean_true_node);
       update_stmt (outer_cond);
+      update_profile_after_ifcombine (inner_cond_bb, outer_cond_bb);
 
       if (dump_file)
        {
@@ -554,6 +602,7 @@ ifcombine_ifandif (basic_block inner_cond_bb, bool inner_inv,
       gimple_cond_set_condition_from_tree (outer_cond,
        outer_inv ? boolean_false_node : boolean_true_node);
       update_stmt (outer_cond);
+      update_profile_after_ifcombine (inner_cond_bb, outer_cond_bb);
 
       if (dump_file)
        {