This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __attribute__((early_branch))
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: Jeff Law <law at redhat dot com>, "cmdLP #CODE" <mccmdlp at gmail dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 3 May 2019 09:11:26 +0200
- Subject: Re: __attribute__((early_branch))
- References: <CAN2=DZzJtpG8Xi8+CtXZ1XQK7Yw7S6-1r3ophX9Y7T5VYESdQQ@mail.gmail.com> <9c490839-079f-d87b-ace6-85f75a0a3258@redhat.com> <CAFiYyc2B21pwzDzj-a7_xsOiOrojdrhcBmE9X8O9kKccKmbwFA@mail.gmail.com> <20190502161648.GH8599@gate.crashing.org>
On Thu, May 2, 2019 at 6:16 PM Segher Boessenkool
<segher@kernel.crashing.org> wrote:
>
> On Thu, May 02, 2019 at 02:17:51PM +0200, Richard Biener wrote:
> > On Tue, Apr 30, 2019 at 9:53 PM Jeff Law <law@redhat.com> wrote:
> > > This is loop unswitching. It's a standard GCC optimization. If it's
> > > not working as well as it should, we're far better off determining why
> > > and fixing the automatic transformation rather than relying on
> > > attributes to drive the transformation.
> >
> > It's currently not implemented for switch () stmts, just for conditionals.
> > This also hurts SPEC cactusADM. There might be a missed-optimization
> > bug about this. A simple recursive implementation might be possible;
> > unswitch one case at a time - maybe order by profile probability. We
> > already recurse on the unswitched bodies (in case multiple conditions
> > can be unswitched)
>
> Well, if for some case value we can prove the controlling expression is
> constant in the loop, we can almost always prove it is constant without
> looking at the case value? So we can pull the whole switch statement
> outside just as easily?
There isn't any infrastructure to "easily" do that (copy the loop N times,
wrap it in a switch stmt and put the N loop copies into the switch cases).
The infrastructure we have (loop versioning) manages to copy a loop once
and wrap the two copies with a conditional. It might be also preferable
to only unswitch the most frequently executed case to avoid code size
explosion (IIRC the cactusADM case has 4 cases, only one is actually
executed).
Richard.
>
>
> Segher