This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Fix over-optimization of calls to pure function
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 20 May 2014 12:47:56 +0200
- Subject: Re: [patch] Fix over-optimization of calls to pure function
- Authentication-results: sourceware.org; auth=none
- References: <5409358 dot 5kA2CkRFhr at polaris> <20140519144228 dot GB12624 at atrey dot karlin dot mff dot cuni dot cz>
> Can't I have sometihng like
>
> loop (i as iterator)
> begin
> I := F(0);
> exception
> when E => N := N + 1;
> end;
>
> here I would expect PRE to discover I as loop invariant that will cause
> exception to be called just once, not at every iteration of loop?
Yet the following testcase passes at -O2:
-- { dg-do run }
-- { dg-options "-O2" }
with Opt35_Pkg; use Opt35_Pkg;
procedure Opt36 is
I : Integer := -1;
N : Natural := 0;
begin
loop
begin
I := I + 1;
I := I + F(0);
exception
when E => N := N +1;
end;
exit when I = 1;
end loop;
if N /= 2 or I = 0 then
raise Program_Error;
end if;
end;
> Can't the same happen for non-call exceptions?
I don't think so, we don't have the equivalent of pure/const for non-call
exceptions, in particular we have side effects.
--
Eric Botcazou