From f1f10541903b082d27114db38947fb31f5364bcc Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 18 Jul 2019 08:24:16 +0000 Subject: [PATCH] Make ifcvt clean up dead comparisons This change is needed to avoid a regression in gcc.dg/ifcvt-3.c for a later patch. Without it, we enter CSE with a dead comparison left by if-conversion and then eliminate the second (live) comparison in favour of the dead one. That's functionally correct in itself, but it meant that we'd combine the subtraction and comparison into a SUBS before we have a chance to fold away the subtraction. 2019-07-18 Richard Sandiford gcc/ * basic-block.h (CLEANUP_FORCE_FAST_DCE): New macro. * cfgcleanup.c (cleanup_cfg): Call run_fast_dce if CLEANUP_FORCE_FAST_DCE is set. * ifcvt.c (rest_of_handle_if_conversion): Pass CLEANUP_FORCE_FAST_DCE to the final cleanup_cfg call if if-conversion succeeded. From-SVN: r273569 --- gcc/ChangeLog | 9 +++++++++ gcc/basic-block.h | 2 ++ gcc/cfgcleanup.c | 8 +++++++- gcc/ifcvt.c | 7 ++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 76baf87d9fc..b545a034e57 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2019-07-18 Richard Sandiford + + * basic-block.h (CLEANUP_FORCE_FAST_DCE): New macro. + * cfgcleanup.c (cleanup_cfg): Call run_fast_dce if + CLEANUP_FORCE_FAST_DCE is set. + * ifcvt.c (rest_of_handle_if_conversion): Pass + CLEANUP_FORCE_FAST_DCE to the final cleanup_cfg call if + if-conversion succeeded. + 2019-07-18 Richard Biener * tree-ssa-sccvn.c (vn_walk_cb_data::push_partial_def): Refactor diff --git a/gcc/basic-block.h b/gcc/basic-block.h index 5e0fbc0e2b3..2a0e8261537 100644 --- a/gcc/basic-block.h +++ b/gcc/basic-block.h @@ -508,6 +508,8 @@ ei_cond (edge_iterator ei, edge *p) #define CLEANUP_CFGLAYOUT 32 /* Do cleanup in cfglayout mode. */ #define CLEANUP_CFG_CHANGED 64 /* The caller changed the CFG. */ #define CLEANUP_NO_PARTITIONING 128 /* Do not try to fix partitions. */ +#define CLEANUP_FORCE_FAST_DCE 0x100 /* Force run_fast_dce to be called + at least once. */ /* Return true if BB is in a transaction. */ diff --git a/gcc/cfgcleanup.c b/gcc/cfgcleanup.c index fca3a084d37..b9307631e1c 100644 --- a/gcc/cfgcleanup.c +++ b/gcc/cfgcleanup.c @@ -3193,7 +3193,10 @@ cleanup_cfg (int mode) && !delete_trivially_dead_insns (get_insns (), max_reg_num ())) break; if ((mode & CLEANUP_CROSSJUMP) && crossjumps_occurred) - run_fast_dce (); + { + run_fast_dce (); + mode &= ~CLEANUP_FORCE_FAST_DCE; + } } else break; @@ -3202,6 +3205,9 @@ cleanup_cfg (int mode) if (mode & CLEANUP_CROSSJUMP) remove_fake_exit_edges (); + if (mode & CLEANUP_FORCE_FAST_DCE) + run_fast_dce (); + /* Don't call delete_dead_jumptables in cfglayout mode, because that function assumes that jump tables are in the insns stream. But we also don't _have_ to delete dead jumptables in cfglayout diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 7b2f6e6bd75..e0c9522057a 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -5457,6 +5457,8 @@ if_convert (bool after_combine) static unsigned int rest_of_handle_if_conversion (void) { + int flags = 0; + if (flag_if_conversion) { if (dump_file) @@ -5466,9 +5468,12 @@ rest_of_handle_if_conversion (void) } cleanup_cfg (CLEANUP_EXPENSIVE); if_convert (false); + if (num_updated_if_blocks) + /* Get rid of any dead CC-related instructions. */ + flags |= CLEANUP_FORCE_FAST_DCE; } - cleanup_cfg (0); + cleanup_cfg (flags); return 0; } -- 2.30.2