]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix factor_out_conditional_operation heuristics for constants
authorAndrew Pinski <quic_apinski@quicinc.com>
Thu, 12 Sep 2024 05:10:53 +0000 (22:10 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Fri, 13 Sep 2024 16:31:06 +0000 (09:31 -0700)
While working on a different patch, I noticed the heuristics were not
doing the right thing if there was statements before the NOP/PREDICTs.
(LABELS don't have other statements before them).

This fixes that oversight which was added in r15-3334-gceda727dafba6e.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* tree-ssa-phiopt.cc (factor_out_conditional_operation): Instead
of just ignorning a NOP/PREDICT, skip over them before checking
the heuristics.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/tree-ssa-phiopt.cc

index 5710bc32e61151411b2df433c96b06470a547173..e5413e405722d5a8245883cfb5062e6bf4e7d89f 100644 (file)
@@ -332,15 +332,17 @@ factor_out_conditional_operation (edge e0, edge e1, gphi *phi,
        {
          gsi = gsi_for_stmt (arg0_def_stmt);
          gsi_prev_nondebug (&gsi);
+         /* Ignore nops, predicates and labels. */
+         while (!gsi_end_p (gsi)
+                 && (gimple_code (gsi_stmt (gsi)) == GIMPLE_NOP
+                     || gimple_code (gsi_stmt (gsi)) == GIMPLE_PREDICT
+                     || gimple_code (gsi_stmt (gsi)) == GIMPLE_LABEL))
+           gsi_prev_nondebug (&gsi);
+
          if (!gsi_end_p (gsi))
            {
              gimple *stmt = gsi_stmt (gsi);
-             /* Ignore nops, predicates and labels. */
-             if (gimple_code (stmt) == GIMPLE_NOP
-                 || gimple_code (stmt) == GIMPLE_PREDICT
-                 || gimple_code (stmt) == GIMPLE_LABEL)
-               ;
-             else if (gassign *assign = dyn_cast <gassign *> (stmt))
+             if (gassign *assign = dyn_cast <gassign *> (stmt))
                {
                  tree lhs = gimple_assign_lhs (assign);
                  enum tree_code ass_code