https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85987

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-05-30
                 CC|                            |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  With recent improvement (r258645) I explicitely preserved that
behavior which is easy to fix for the testcase:

Index: gcc/tree-ssa-phiopt.c
===================================================================
--- gcc/tree-ssa-phiopt.c       (revision 260950)
+++ gcc/tree-ssa-phiopt.c       (working copy)
@@ -2049,7 +2049,7 @@ single_trailing_store_in_bb (basic_block
     return NULL;

   /* Verify there is no other store in this BB.  */
-  if (!SSA_NAME_IS_DEFAULT_DEF (gimple_vuse (store))
+  if (0 && !SSA_NAME_IS_DEFAULT_DEF (gimple_vuse (store))
       && gimple_bb (SSA_NAME_DEF_STMT (gimple_vuse (store))) == bb
       && gimple_code (SSA_NAME_DEF_STMT (gimple_vuse (store))) != GIMPLE_PHI)
     return NULL;

Otherwise the code should be able to sink them but the dependence analysis it
performs (when vectorization or if-conversion is enabled, see
max-stores-to-sink param) is too conservative and considering unrelated
dependences (here between
mod and t which alias) for its analysis.

The reason for the heuristic of by default only handling single-store BBs
is that it should be an enabler for if-conversion and if there's a
conditional store remaining that wouldn't work and thus the transform might
not be profitable (it might increase register pressure and cause spilling,
it might need a copy on one of the edges into the store if coalescing
doesn't work, etc. - so it needs a better cost model for that).  Originally
the heuristic was there was to be a single _stmt_ in the BB being a store
thus even stricter.

Note this particular patch also breaks things so that the code for
more-than-one-store-in-the-BB is never executed.  Consider

int t, mod;
void CreateChecksum(int isTestNet) {
    if (isTestNet == 0) {
        mod = (5);
        t += 1;
    } else {
        mod = (9);
    }
}

which is no longer optimized after the "patch".

Reply via email to