[Ada] Implement Machine_Rounding attribute in line when possible

GNAT implements Machine_Rounding as an alias for Rounding but, whereas
the implementation of the latter is in line when possible, that of the
former is always out of line, which is not aligned with the intent of
the Ada RM.

This changes the compiler to using for Machine_Rounding the same in line
implementation as Rounding when possible.

Running these commands:

  gcc -c f.adb -gnatD
  grep system f.adb.dg

On the following sources:

function F (Val : Float) return Integer is
begin
  return Integer (Float'Machine_Rounding (Val));
end;

Should execute silently.

2019-09-19  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* exp_attr.adb (Is_Inline_Floating_Point_Attribute): Treat
	Machine_Rounding as an alias for Rounding.
	* sem_res.adb (Simplify_Type_Conversion): Likewise.

From-SVN: r275943
This commit is contained in:
Eric Botcazou 2019-09-19 08:13:38 +00:00 committed by Pierre-Marie de Rodat
parent 143df1f9aa
commit d8ec2787e0
3 changed files with 15 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2019-09-19 Eric Botcazou <ebotcazou@adacore.com>
* exp_attr.adb (Is_Inline_Floating_Point_Attribute): Treat
Machine_Rounding as an alias for Rounding.
* sem_res.adb (Simplify_Type_Conversion): Likewise.
2019-09-19 Gary Dismukes <dismukes@adacore.com>
* exp_unst.adb (Unnest_Subprogram): Bypass the transformation of

View File

@ -8360,13 +8360,13 @@ package body Exp_Attr is
return False;
end if;
-- Here we are in the integer conversion context
-- Here we are in the integer conversion context. We reuse Rounding for
-- Machine_Rounding as System.Fat_Gen, which is a permissible behavior.
-- Very probably we should also recognize the cases of Machine_Rounding
-- and unbiased rounding in this conversion context, but the back end is
-- not yet prepared to handle these cases ???
return Id = Attribute_Rounding or else Id = Attribute_Truncation;
return
Id = Attribute_Rounding
or else Id = Attribute_Machine_Rounding
or else Id = Attribute_Truncation;
end Is_Inline_Floating_Point_Attribute;
end Exp_Attr;

View File

@ -12439,7 +12439,8 @@ package body Sem_Res is
-- ityp (x)
-- with the Float_Truncate flag set to False or True respectively,
-- which is more efficient.
-- which is more efficient. We reuse Rounding for Machine_Rounding
-- as System.Fat_Gen, which is a permissible behavior.
if Is_Floating_Point_Type (Opnd_Typ)
and then
@ -12448,6 +12449,7 @@ package body Sem_Res is
and then Conversion_OK (N)))
and then Nkind (Operand) = N_Attribute_Reference
and then Nam_In (Attribute_Name (Operand), Name_Rounding,
Name_Machine_Rounding,
Name_Truncation)
then
declare