> > In response to PR87105 I dusted off an old patch that adds an early > phiopt pass. Recognizing we run phiopt twice with not many passes > in between early in post-IPA optimizations this patch moves the > first of said to the early pipeline. > > The main motivation is to do things like MIN/MAX_EXPR early to > avoid jump threading mess up the CFG (the case with PR87105). > I realize theres early backward threading before the new early > phiopt pass but that doesn't seem to do anything useful there (yet). > I think it makes sense to push that later anyways.
This looks like good plan overall. > > Now, early phiopt is quite confused about predict stmts still > being present and turning conditional BBs into diamonds which it > cannot handle. I've fixed at least stray such stmts in the BBs > that are interesting. Note this may hide fallout which would otherwise > be visible in the testsuite (there's no flag to avoid > generating the predictors - they are emitted directly by the frontends, > maybe we could drop them with -fno[-guess]-branch-probabilities at > gimplification time?). That would be fine with me. We could also just add guess-branch-probaiblities guards and not produce them from FE. > diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c > index cf12cb1f391..938ad7d9a44 100644 > --- a/gcc/tree-cfg.c > +++ b/gcc/tree-cfg.c > @@ -6106,11 +6106,19 @@ gimple_empty_block_p (basic_block bb) > gimple_stmt_iterator gsi = gsi_after_labels (bb); > if (phi_nodes (bb)) > return false; > - if (gsi_end_p (gsi)) > - return true; > - if (is_gimple_debug (gsi_stmt (gsi))) > - gsi_next_nondebug (&gsi); > - return gsi_end_p (gsi); > + while (!gsi_end_p (gsi)) > + { > + gimple *stmt = gsi_stmt (gsi); > + if (is_gimple_debug (stmt)) > + ; > + else if (gimple_code (stmt) == GIMPLE_NOP > + || gimple_code (stmt) == GIMPLE_PREDICT) > + ; > + else > + return false; > + gsi_next (&gsi); > + } > + return true; I think considering GIMPLE_PREDICT as empty basic blocks is going to make cfgcleanup to drop them in cases it should not (it will simply forward edges across them). I guess we could add new flag to gimple_empty_block_p whether to skip them or not defaulting to false. Once you ifconvert diamond you want to drop all predict statemetns inside of the diamond because they used to control the condtional of the diamond and now they control something else. Honza > } > > > diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c > index 1667bad873b..bbefc21dc13 100644 > --- a/gcc/tree-ssa-phiopt.c > +++ b/gcc/tree-ssa-phiopt.c > @@ -913,7 +913,9 @@ value_replacement (basic_block cond_bb, basic_block > middle_bb, > gsi_next_nondebug (&gsi); > if (!is_gimple_assign (stmt)) > { > - emtpy_or_with_defined_p = false; > + if (gimple_code (stmt) != GIMPLE_PREDICT > + && gimple_code (stmt) != GIMPLE_NOP) > + emtpy_or_with_defined_p = false; > continue; > } > /* Now try to adjust arg0 or arg1 according to the computation