From: Kyrylo Tkachov <[email protected]>

Several helpers BITMAP_ALLOC a local bitmap and BITMAP_FREE it on every exit,
which is easy to get wrong when a new exit is added.  Convert them all to
auto_bitmap.

dead_or_predicable had three: merge_set, live and return_regs.  merge_set was
a null-or-allocated sentinel guarding the PR46315 REG_EQUAL note scrubbing;
an auto_bitmap that is only populated on the path that moves insns is
equivalent, because the scrubbing loop does nothing when the bitmap is empty.
The others - bbs_ok_for_cmove_arith is bba_sets, bb_valid_for_noce_process_p
is test_bb_temps (whose free_bitmap_and_fail goto label goes away too), and
noce_convert_multiple_sets is set_targets - are straight conversions.  No
functional change.

gcc/ChangeLog:

        * ifcvt.cc (dead_or_predicable): Make merge_set, live and return_regs
        auto_bitmap and drop the manual BITMAP_FREE calls.
        (bbs_ok_for_cmove_arith): Make bba_sets an auto_bitmap.
        (bb_valid_for_noce_process_p): Make test_bb_temps an auto_bitmap and
        return directly instead of jumping to a cleanup label.
        (noce_convert_multiple_sets): Make set_targets an auto_bitmap.

Signed-off-by: Kyrylo Tkachov <[email protected]>
---
 gcc/ifcvt.cc | 62 ++++++++++++++--------------------------------------
 1 file changed, 17 insertions(+), 45 deletions(-)

diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc
index 0a2e60bce23..1ee49e9c2d3 100644
--- a/gcc/ifcvt.cc
+++ b/gcc/ifcvt.cc
@@ -2548,7 +2548,7 @@ static bool
 bbs_ok_for_cmove_arith (basic_block bb_a, basic_block bb_b, rtx to_rename)
 {
   rtx_insn *a_insn;
-  bitmap bba_sets = BITMAP_ALLOC (&reg_obstack);
+  auto_bitmap bba_sets (&reg_obstack);
 
   df_ref def;
   df_ref use;
@@ -2562,7 +2562,6 @@ bbs_ok_for_cmove_arith (basic_block bb_a, basic_block 
bb_b, rtx to_rename)
 
       if (!sset_a)
        {
-         BITMAP_FREE (bba_sets);
          return false;
        }
       /* Record all registers that BB_A sets.  */
@@ -2582,7 +2581,6 @@ bbs_ok_for_cmove_arith (basic_block bb_a, basic_block 
bb_b, rtx to_rename)
 
       if (!sset_b)
        {
-         BITMAP_FREE (bba_sets);
          return false;
        }
 
@@ -2598,7 +2596,6 @@ bbs_ok_for_cmove_arith (basic_block bb_a, basic_block 
bb_b, rtx to_rename)
       else if (!REG_P (SET_DEST (sset_b))
               && !paradoxical_subreg_p (SET_DEST (sset_b)))
        {
-         BITMAP_FREE (bba_sets);
          return false;
        }
 
@@ -2607,14 +2604,12 @@ bbs_ok_for_cmove_arith (basic_block bb_a, basic_block 
bb_b, rtx to_rename)
        {
          if (bitmap_bit_p (bba_sets, DF_REF_REGNO (use)))
            {
-             BITMAP_FREE (bba_sets);
              return false;
            }
        }
 
     }
 
-  BITMAP_FREE (bba_sets);
   return true;
 }
 
@@ -3951,7 +3946,7 @@ bb_valid_for_noce_process_p (basic_block test_bb, rtx 
cond,
   if (REG_P (x) && reg_set_between_p (x, first_insn, prev_last_insn))
     return false;
 
-  bitmap test_bb_temps = BITMAP_ALLOC (&reg_obstack);
+  auto_bitmap test_bb_temps (&reg_obstack);
 
   /* The regs that are live out of test_bb.  */
   bitmap test_bb_live_out = df_get_live_out (test_bb);
@@ -3966,7 +3961,7 @@ bb_valid_for_noce_process_p (basic_block test_bb, rtx 
cond,
            continue;
 
          if (!insn_valid_noce_process_p (insn, cc))
-           goto free_bitmap_and_fail;
+           return false;
 
          rtx sset = single_set (insn);
          gcc_assert (sset);
@@ -3977,7 +3972,7 @@ bb_valid_for_noce_process_p (basic_block test_bb, rtx 
cond,
          if (contains_mem_rtx_p (SET_SRC (sset))
              || !REG_P (dest)
              || reg_overlap_mentioned_p (dest, cond))
-           goto free_bitmap_and_fail;
+           return false;
 
          potential_cost += pattern_cost (sset, speed_p);
          bitmap_set_bit (test_bb_temps, REGNO (dest));
@@ -3987,16 +3982,11 @@ bb_valid_for_noce_process_p (basic_block test_bb, rtx 
cond,
   /* If any of the intermediate results in test_bb are live after test_bb
      then fail.  */
   if (bitmap_intersect_p (test_bb_live_out, test_bb_temps))
-    goto free_bitmap_and_fail;
+    return false;
 
-  BITMAP_FREE (test_bb_temps);
   *cost += potential_cost;
   *simple_p = false;
   return true;
-
- free_bitmap_and_fail:
-  BITMAP_FREE (test_bb_temps);
-  return false;
 }
 
 /* Helper function to emit a cmov sequence encapsulated in
@@ -4220,7 +4210,7 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
      have the same target.  */
   unsigned i;
   noce_multiple_sets_info *info;
-  bitmap set_targets = BITMAP_ALLOC (&reg_obstack);
+  auto_bitmap set_targets (&reg_obstack);
   FOR_EACH_VEC_ELT_REVERSE (insn_info, i, info)
     {
       gcc_checking_assert (REG_P (info->target));
@@ -4231,7 +4221,6 @@ noce_convert_multiple_sets (struct noce_if_info *if_info)
 
       bitmap_set_bit (set_targets, REGNO (info->target));
     }
-  BITMAP_FREE (set_targets);
 
   /* Actually emit the sequence if it isn't too expensive.  */
   rtx_insn *seq = get_insns ();
@@ -6580,7 +6569,7 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
   rtx_insn *head, *end, *jump;
   rtx_insn *earliest = NULL;
   rtx old_dest;
-  bitmap merge_set = NULL;
+  auto_bitmap merge_set (&reg_obstack);
   /* Number of pending changes.  */
   int n_validated_changes = 0;
   rtx new_dest_label = NULL_RTX;
@@ -6705,7 +6694,6 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
     {
       rtx cond;
       rtx_insn *insn;
-      regset live;
       bool success;
 
       /* In the non-conditional execution case, we have to verify that there
@@ -6720,18 +6708,15 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
       if (!cond)
        return false;
 
-      live = BITMAP_ALLOC (&reg_obstack);
+      auto_bitmap live (&reg_obstack);
       simulate_backwards_to_point (merge_bb, live, end);
       success = can_move_insns_across (head, end, earliest, jump,
                                       merge_bb, live,
                                       df_get_live_in (other_bb), NULL);
-      BITMAP_FREE (live);
       if (!success)
        return false;
 
       /* Collect the set of registers set in MERGE_BB.  */
-      merge_set = BITMAP_ALLOC (&reg_obstack);
-
       FOR_BB_INSNS (merge_bb, insn)
        if (NONDEBUG_INSN_P (insn))
          df_simulate_find_defs (insn, merge_set);
@@ -6748,10 +6733,9 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
          && single_succ (new_dest) == EXIT_BLOCK_PTR_FOR_FN (cfun)
          && bitmap_intersect_p (df_get_live_in (new_dest), merge_set))
        {
-         regset return_regs;
          unsigned int i;
 
-         return_regs = BITMAP_ALLOC (&reg_obstack);
+         auto_bitmap return_regs (&reg_obstack);
 
          /* Start off with the intersection of regs used to pass
             params and regs used to return values.  */
@@ -6781,13 +6765,8 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
                        }
                  }
              if (bitmap_intersect_p (merge_set, return_regs))
-               {
-                 BITMAP_FREE (return_regs);
-                 BITMAP_FREE (merge_set);
-                 return false;
-               }
+               return false;
            }
-         BITMAP_FREE (return_regs);
        }
     }
 
@@ -6859,17 +6838,13 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
        } while (insn != end && (insn = NEXT_INSN (insn)));
 
       /* PR46315: when moving insns above a conditional branch, the REG_EQUAL
-        notes referring to the registers being set might become invalid.  */
-      if (merge_set)
-       {
-         unsigned i;
-         bitmap_iterator bi;
-
-         EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
-           remove_reg_equal_equiv_notes_for_regno (i);
-
-         BITMAP_FREE (merge_set);
-       }
+        notes referring to the registers being set might become invalid.
+        MERGE_SET is empty on the conditional-execution path, which does not
+        move anything.  */
+      unsigned i;
+      bitmap_iterator bi;
+      EXECUTE_IF_SET_IN_BITMAP (merge_set, 0, i, bi)
+       remove_reg_equal_equiv_notes_for_regno (i);
 
       reorder_insns (head, end, PREV_INSN (earliest));
     }
@@ -6888,9 +6863,6 @@ dead_or_predicable (basic_block test_bb, basic_block 
merge_bb,
  cancel:
   cancel_changes (0);
 
-  if (merge_set)
-    BITMAP_FREE (merge_set);
-
   return false;
 }
 
-- 
2.50.1 (Apple Git-155)

Reply via email to