On 9/23/2021 5:15 AM, Aldy Hernandez wrote:
My upcoming improvements to the forward jump threader make it thread
more aggressively.  In investigating some "regressions", I noticed
that it has always allowed threading through empty latches and across
loop boundaries.  As we have discussed recently, this should be avoided
until after loop optimizations have run their course.

Note that this wasn't much of a problem before because DOM/VRP
couldn't find these opportunities, but with a smarter solver, we trip
over them more easily.
We used to be much more aggressive in this space -- but we removed the equivalency tracking on backedges in the main part of DOM which had the side effect to reducing the number of threads related to back edges in loops.

Of course that was generally a positive thing given the issues we've been discussing.



Because the forward threader doesn't have an independent localized cost
model like the new threader (profitable_path_p), it is difficult to
catch these things at discovery.  However, we can catch them at
registration time, with the added benefit that all the threaders
(forward and backward) can share the handcuffs.
In an ideal world profitability and correctness would be separated -- but they're still intertwined and I don't think this makes that situation particularly worse.  And I do like that having a single choke point.

Obviously you're cleaning this up, so I think a significant degree of freedom should be given here....



This patch is an adaptation of what we do in the backward threader, but
it is not meant to catch everything we do there, as some of the
restrictions there are due to limitations of the different block
copiers (for example, the generic copier does not re-use existing
threading paths).

We could ideally remove the now redundant bits in profitable_path_p, but
I would prefer not to for two reasons.  First, the backward threader uses
profitable_path_p as it discovers paths to avoid discovering paths in
unprofitable directions.  Second, I would like to merge all the forward
cost restrictions into the profitability class in the backward threader,
not the other way around.  Alas, that reshuffling will have to wait for
the next release.

As usual, there are quite a few tests that needed adjustments.  It seems
we were quite happily threading improper scenarios.  With most of them,
as can be seen in pr77445-2.c, we're merely shifting the threading to
after loop optimizations.

Tested on x86-64 Linux.

OK for trunk?

p.s. "Sure, sounds like fun... how hard can improving the threaders be?"

gcc/ChangeLog:

        * tree-ssa-threadupdate.c (jt_path_registry::cancel_invalid_paths):
        New.
        (jt_path_registry::register_jump_thread): Call
        cancel_invalid_paths.
        * tree-ssa-threadupdate.h (class jt_path_registry): Add
        cancel_invalid_paths.

gcc/testsuite/ChangeLog:

        * gcc.dg/tree-ssa/20030714-2.c: Adjust.
        * gcc.dg/tree-ssa/pr66752-3.c: Adjust.
        * gcc.dg/tree-ssa/pr77445-2.c: Adjust.
        * gcc.dg/tree-ssa/ssa-dom-thread-18.c: Adjust.
        * gcc.dg/tree-ssa/ssa-dom-thread-7.c: Adjust.
        * gcc.dg/vect/bb-slp-16.c: Adjust.
OK
jeff

Reply via email to