This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix over-optimization of calls to pure function


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]