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: [PING] ada: Various patches


On  9/04, Arnaud Charlet wrote:

| Here is Robert's initial analysis of this patch, which is not
| suitable in the submitted form:
| 
| <<
|  The patch as stated is certainly wrong (the test should just
|  be for Signed_Integer instead of Integer).
| 
|  Ah, I see the problem, normal modular types are fine
|  e.g. 2**32, it is just weird modular types where the
|  result is wrong, the patch should be refined not to lose
|  the useful case!
| 
|  May be useful to introduce Is_Strange_Modular_Type :-)
| >>

Well, the patch is not wrong, as it fixes a bad code generation bug, but
it is too enthusiastic in disabling the optimization.

Would the following patch be more acceptable?

    gcc/ada/
	PR ada/30740
	* exp_ch4.adb (Expand_N_Op_Expon): Do not optimize X*(2**Y) into
	Left_Shift(X, Y) if in a modular context with a non-power of 2 modulus.
	* sem_util.ads, sem_util.adb (Is_Non_Binary_Modular_Type): New.

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index ee440f1..6d77698 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -5499,6 +5499,8 @@ package body Exp_Ch4 is
          begin
             if (Nkind (P) = N_Op_Multiply
                  and then
+                   not Is_Non_Binary_Modular_Type (Typ)
+                 and then
                    ((Is_Integer_Type (Etype (L)) and then R = N)
                        or else
                     (Is_Integer_Type (Etype (R)) and then L = N))
diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb
index 54925d7..38796a6 100644
--- a/gcc/ada/sem_util.adb
+++ b/gcc/ada/sem_util.adb
@@ -6321,6 +6321,16 @@ package body Sem_Util is
       end if;
    end Is_Local_Variable_Reference;
 
+   --------------------------------
+   -- Is_Non_Binary_Modular_Type --
+   --------------------------------
+
+   function Is_Non_Binary_Modular_Type (E : Entity_Id) return Boolean is
+   begin
+      return Is_Modular_Integer_Type (E)
+        and then Non_Binary_Modulus (Base_Type (E));
+   end Is_Non_Binary_Modular_Type;
+
    -------------------------
    -- Is_Object_Reference --
    -------------------------
diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads
index c47af51..cf771d8 100644
--- a/gcc/ada/sem_util.ads
+++ b/gcc/ada/sem_util.ads
@@ -694,6 +694,10 @@ package Sem_Util is
    --  mode parameter of the current enclosing subprogram.
    --  Why are OUT parameters not considered here ???
 
+   function Is_Non_Binary_Modular_Type (E : Entity_Id) return Boolean;
+   --  Return True if E is a modular integer type with a non-power-of-two
+   --  modulus.
+
    function Is_Object_Reference (N : Node_Id) return Boolean;
    --  Determines if the tree referenced by N represents an object. Both
    --  variable and constant objects return True (compare Is_Variable).


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