https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104356
--- Comment #46 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> I meant something like:
> with System.Unsigned_Types; use System.Unsigned_Types;
>
> function F (X, Y : Unsigned) return Unsigned is
> Z : Unsigned;
> begin
> if X >=2 then
> return 0;
> end if;
> Z := Y;
> if X = 1 then
> Z := Y + 4;
> end if;
> return Z / X;
> end;
> and there evrp does with -O2 -gnatp optimize away the division.
My bad. I forgot that -gnatp now disables -fnon-call-exceptions too (in order
to make the mode mimic C++) so the testcase must be written:
with System.Unsigned_Types; use System.Unsigned_Types;
function Opt97 (X, Y : Unsigned) return Unsigned is
pragma Suppress (All_Checks);
Z : Unsigned;
begin
if X >= 2 then
return 0;
end if;
Z := Y;
if X = 1 then
Z := Y + 4;
end if;
return Z / X;
end;
and there is still the divide at -O2 and above on mainline.