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

--- Comment #23 from Jeffrey A. Law <law at redhat dot com> ---
The model of shortening as much as possible for gimple, then widening to word
mode at the gimple/RTL boundary is probably too simplistic.  We really need the
ability to widen when doing so allows for simplification.

That's what the prototype pattern I posted was meant to show.  By widening we
can expose the common subexpressions, and once the common subexpressions are
exposed, min/max can do its job.  The problem is we don't have range data, so
we have to do masking of the result, nor do we know if the widened operand is a
common subexpression or not.  Thus profitability is unknown at transformation
time.

I was about to write off VRP again because it lacks much of the CSE capability
we want, but VRP has the information to know that the result is value
preserving if done in the wider mode.  So at VRP time we could do the widening
without needing to mask the result, at which point widening is known to be
profitable.  As written we have two casts + addition.  VRP could turn that into
a addition with a single cast (both of which are common subexpressions, but VRP
doesn't need to detect that to ensure profitability).

DOM/FRE have CSE infrastructure, but the range data presented to them is not
path sensitive and thus useless in this case.

I'm hesitant to try to do all this in phi-opt -- phi-opt would have to look
through the casts, prove equivalences, etc.  ick.

Reply via email to