From mboxrd@z Thu Jan 1 00:00:00 1970 From: Corey Minyard To: Richard Henderson Cc: gcc@gcc.gnu.org Subject: Re: Loop optimization bug with Ada front end on PPC (and probably Alpha) Date: Sun, 25 Nov 2001 15:06:00 -0000 Message-ID: <3C0179C5.2090002@acm.org> References: <3BFCA770.5070304@acm.org> <20011124124100.A2485@redhat.com> X-SW-Source: 2001-11/msg01211.html Message-ID: <20011125150600.LROSFwlcpAXFXPVSXLPqKa2E-BQrJ8Yb-tvea37N_gs@z> Richard Henderson wrote: >On Thu, Nov 22, 2001 at 01:21:20AM -0600, Corey Minyard wrote: > >> for I in 1 .. Len loop >> a[i] := b[i]; >> end loop; >> > >Give me a complete compilable testcase and I'll look at it. > > >r~ > The following shows the problem: procedure Ada.Tster (S : in out String; Len : in out Integer) is begin Len := 0; for I in 1 .. S'Length loop if S (I) /= ' ' then Len := Len + 1; S (Len) := S (I); end if; end loop; end Ada.Tster; Unfortunately, it's not simple to reproduce this, since you have to build an Ada cross compiler, and you have to compile this code as part of the compiler (since you can't compile anything else easily without having gnatlib compiled and installed) And it's not the same as the one reported by Andreas Schwab; I don't think you can reproduce this particular bug with the C compiler. You have to jump past the increment to enter the loop, but the jump has to be after the loop begin note. I have attached a patch that is less of a cheap hack than the previous one, it scans the insns of the loop to detect the situation. With this patch I can do a full bootstrap on the PowerPC. Another way to solve this problem would be to move the jump past the increment to before the loop begin note; the doloop code will detect this and not apply the doloop optimization, but then no for loops from the Ada front-end will have doloop optimization. The attached patch might be done in a simpler manner, but I don't know the code well enought right now to know, and I couldn't find a better way in a quick search. It was more complicated than I like because in some loop the increment variable is not the same one that is incremented, another variable is incremented then assigned to the increment variable. This code only handles one level of assignment, it might be necessary to have more. -Corey