]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PHIOPT: Ignore predicates for match-and-simplify phi-opt
authorAndrew Pinski <apinski@marvell.com>
Sun, 9 Apr 2023 22:47:50 +0000 (22:47 +0000)
committerAndrew Pinski <apinski@marvell.com>
Mon, 24 Apr 2023 15:50:07 +0000 (08:50 -0700)
This fixes a missed optimization where early phi-opt would
not work when there was predicates. The easiest fix is
to change empty_bb_or_one_feeding_into_p to ignore those
statements while checking for only feeding statement.

Note phi-opt-23.c and phi-opt-24.c still fail as we don't handle
diamond form in match_and_simplify phiopt yet.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p):
Instead of calling last_and_only_stmt, look for the last statement
manually.

gcc/testsuite/ChangeLog:

* gcc.dg/tree-ssa/ssa-ifcombine-13.c: Add -fno-ssa-phiopt.

gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c
gcc/tree-ssa-phiopt.cc

index 425eb3d64811a7d008fad70768e934b4ee38a275..7976544c79ba73578e5c59651b696eeec5faffc8 100644 (file)
@@ -1,5 +1,7 @@
 /* { dg-do compile } */
-/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1" } */
+/* Disable phi-opt as it is no longer confused by predicate which had allowed ifcombine to work in the past.
+   Note this testcase is about ifcombine rather than phi-opt. */
+/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1 -fno-ssa-phiopt" } */
 
 _Bool f1(_Bool a, _Bool b)
 {
index f3164b8511b76685f0740ecc9767fbc3bb099962..f17c3507d115d4a1be13736b538ddb9c52bef042 100644 (file)
@@ -960,9 +960,27 @@ empty_bb_or_one_feeding_into_p (basic_block bb,
   if (!gimple_seq_empty_p (phi_nodes (bb)))
     return false;
 
-  stmt_to_move = last_and_only_stmt (bb);
+  gimple_stmt_iterator gsi;
+
+  gsi = gsi_start_nondebug_after_labels_bb (bb);
+  while (!gsi_end_p (gsi))
+    {
+      gimple *s = gsi_stmt (gsi);
+      gsi_next_nondebug (&gsi);
+      /* Skip over Predict and nop statements. */
+      if (gimple_code (s) == GIMPLE_PREDICT
+         || gimple_code (s) == GIMPLE_NOP)
+       continue;
+      /* If there is more one statement return false. */
+      if (stmt_to_move)
+       return false;
+      stmt_to_move = s;
+    }
+
+  /* The only statement here was a Predict or a nop statement
+     so return true. */
   if (!stmt_to_move)
-    return false;
+    return true;
 
   if (gimple_vuse (stmt_to_move))
     return false;