https://gcc.gnu.org/g:7023e340a9a1e1d217ec79756ee2ac6bd2b527b6
commit r17-4035-g7023e340a9a1e1d217ec79756ee2ac6bd2b527b6 Author: Kyrylo Tkachov <[email protected]> Date: Sun Sep 6 13:15:35 2026 +0200 ifcvt: drop three vacuous tests noce_try_shifted_store_flag tests COMMON for null after it has already returned unless CODE was set, and only the two arms that set COMMON set CODE. noce_try_store_flag_mask decides which arm is the zero one with an assignment inside a disjunction, which leaves REVERSEP true on the path that matches nothing. Test for the two forms separately. noce_convert_multiple_sets calls set_used_flags on the two condition operands after calling it on the condition, which already walks into them. That was their only use, so the locals go too. No functional change. gcc/ChangeLog: * ifcvt.cc (noce_try_shifted_store_flag): Drop the vacuous null test on common. (noce_try_store_flag_mask): Match the two forms without assigning inside the condition. (noce_convert_multiple_sets): Drop the redundant set_used_flags calls and the locals they were the only use of. Signed-off-by: Kyrylo Tkachov <[email protected]> Diff: --- gcc/ifcvt.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc index 6941bcde5b87..dc1a781e691f 100644 --- a/gcc/ifcvt.cc +++ b/gcc/ifcvt.cc @@ -1814,7 +1814,7 @@ noce_try_shifted_store_flag (struct noce_if_info *if_info) start_sequence (); /* If X and COMMON are the same, then we're going to need a temporary. */ - if (common && rtx_equal_p (common, if_info->x)) + if (rtx_equal_p (common, if_info->x)) { common = gen_reg_rtx (mode); noce_emit_move_insn (common, if_info->x); @@ -2268,19 +2268,22 @@ noce_try_store_flag_mask (struct noce_if_info *if_info) { rtx target; rtx_insn *seq; - bool reversep; if (!noce_simple_bbs (if_info)) return false; - reversep = false; + /* Match "if (test) x = 0;" and, with the arms the other way round, + "if (!test) x = 0;". */ + bool zero_a = (if_info->a == const0_rtx + && (REG_P (if_info->b) + || rtx_equal_p (if_info->b, if_info->x))); + bool zero_b = (if_info->b == const0_rtx + && (REG_P (if_info->a) + || rtx_equal_p (if_info->a, if_info->x))); - if ((if_info->a == const0_rtx - && (REG_P (if_info->b) || rtx_equal_p (if_info->b, if_info->x))) - || ((reversep = true) - && if_info->b == const0_rtx - && (REG_P (if_info->a) || rtx_equal_p (if_info->a, if_info->x)))) + if (zero_a || zero_b) { + bool reversep = !zero_a; start_sequence (); target = noce_emit_store_flag (if_info, gen_reg_rtx (GET_MODE (if_info->x)), @@ -4154,8 +4157,6 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) /* Decompose the condition attached to the jump. */ rtx cond = noce_get_condition (jump, &cond_earliest, false); - rtx x = XEXP (cond, 0); - rtx y = XEXP (cond, 1); auto_delete_vec<noce_multiple_sets_info> insn_info; init_noce_multiple_sets_info (then_bb, insn_info); @@ -4280,8 +4281,6 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) } set_used_flags (cond); - set_used_flags (x); - set_used_flags (y); unshare_all_rtl_in_chain (seq); end_sequence ();
