On Tue, Oct 27, 2026 at 7:56 AM Jeff Law <[email protected]> wrote:
> I'd lean towards taking the regression on the diagnostic and picking up
> the optimization, particularly since the regression is only with -O1.
> Understanding the sequence of events that allows the unpatched compiler
> to optimize the code well enough to make tree-ssa-uninit happy would be
> helpful, particularly when comparing it to what the patched compiler does.
Agreed on the direction. Here is the sequence of events.
uninit-pr44547.c has an outer switch on the parameter 'argc' with cases
{1,2,4}, and inside it an inner switch on the same 'argc' that assigns
'n' only in those three cases and then returns 'n'. The inner switch's
default branch, which leaves 'n' uninitialized, is unreachable because the
outer switch already restricts argc to {1,2,4}.
Unpatched -O1: pass_lower_switch runs early, right after
pass_lower_vector_ssa, and turns both switches into decision trees. The
jump-threading passes that run after it (pass_thread_jumps, the second
pass_dominator, and the second pass_thread_jumps_full) then thread the
three outer-switch edges (argc == 1/2/4) through the lowered inner
decision tree, which proves the inner default edge dead, and the
following DCE removes it. By the time pass_late_warn_uninitialized runs,
no edge carries uninitialized 'n' into the return, so there is nothing to
warn about. The unpatched compiler gets this right only indirectly: the
threader happens to delete the dead edge before the uninit pass looks.
Patched -O1: with pass_lower_switch moved to just before the final VRP it
now runs after the second pass_thread_jumps_full, so the switch is still a
GIMPLE_SWITCH when the threading passes run and the inner switch is not
threaded. After the lowering the only passes left before
pass_late_warn_uninitialized are pass_vrp (final), pass_ccp, and the
simple cleanups (DSE/DCE/forwprop/phiopt/cd_dce/sccopy). At -O1
flag_tree_vrp is off (it is enabled from -O2 up), so VRP does not run;
pass_ccp only propagates constants and cannot use the range argc in
{1,2,4}; and none of the cleanups thread or range-propagate. The dead
default edge therefore survives into the uninit pass, whose predicate
analysis reasons about control dependence only, not value ranges, and so
cannot prove the edge unreachable -- the false positive.
So the regression is a latent limitation of the uninit analysis that the
reordering merely exposes; it was previously masked by the threader having
removed the dead edge. Rather than accepting the -O1 warning I have a
small follow-up that makes the uninit analysis range-aware: it enables a
ranger for the pass and, when every maybe-undefined PHI operand arrives on
an edge whose controlling condition has an empty range on that edge,
treats the PHI as guarded. That prunes the dead default edge directly and
makes the reordering zero-regression. I'll send the pass-reorder plus the
uninit-analysis fix as a two-patch series.
Sendao