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: [gfortran] Updates to ISHFT translation


Steven Bosscher wrote:
>>-  /* Right shift if negative.  */
>>-  rshift = convert (type, fold (build2 (RSHIFT_EXPR, utype, arg, width)));
>>+  /* Right shift if negative.
>>+     We convert to an unsigned type because we want a logical shift.
>>+     The standard doesn't define the case of shifting negative
>>+     numbers, and we try to be compatible with other compilers, most
>>+     notably g77, here.  */
>>+  rshift = convert (type, 
>>+                   fold (build2 (RSHIFT_EXPR, utype, 
>>+                                 convert (type, arg), width)));
> 
> 
> Why convert there instead of fold_convert?

Because I wasn't aware of its existence.  Looking at it, I'm not sure what the
comment in front of fold_convert should mean to me:
/* Convert expression ARG to type TYPE.  Used by the middle-end for
   simple conversions in preference to calling the front-end's convert.  */
So, in which ways is this semantically different from convert (type, fold (...))

Anyway, updated patch attached, same ChangeLog, testing in progress.

- Tobi

Index: trans-intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-intrinsic.c,v
retrieving revision 1.38
diff -u -p -r1.38 trans-intrinsic.c
--- trans-intrinsic.c	8 Jan 2005 21:47:36 -0000	1.38
+++ trans-intrinsic.c	9 Jan 2005 16:59:21 -0000
@@ -1785,18 +1785,18 @@ gfc_conv_intrinsic_ishft (gfc_se * se, g
   type = TREE_TYPE (arg);
   utype = gfc_unsigned_type (type);
 
-  /* We convert to an unsigned type because we want a logical shift.
-     The standard doesn't define the case of shifting negative
-     numbers, and we try to be compatible with other compilers, most
-     notably g77, here.  */
-  arg = convert (utype, arg);
   width = fold (build1 (ABS_EXPR, TREE_TYPE (arg2), arg2));
 
   /* Left shift if positive.  */
   lshift = fold (build2 (LSHIFT_EXPR, type, arg, width));
 
-  /* Right shift if negative.  */
-  rshift = convert (type, fold (build2 (RSHIFT_EXPR, utype, arg, width)));
+  /* Right shift if negative.
+     We convert to an unsigned type because we want a logical shift.
+     The standard doesn't define the case of shifting negative
+     numbers, and we try to be compatible with other compilers, most
+     notably g77, here.  */
+  rshift = fold_convert (type, build2 (RSHIFT_EXPR, utype, 
+				       convert (type, arg), width));
 
   tmp = fold (build2 (GE_EXPR, boolean_type_node, arg2,
 		      convert (TREE_TYPE (arg2), integer_zero_node)));
@@ -1807,12 +1807,10 @@ gfc_conv_intrinsic_ishft (gfc_se * se, g
      special case.  */
   num_bits = convert (TREE_TYPE (arg2),
 		      build_int_cst (NULL, TYPE_PRECISION (type)));
-  cond = fold (build2 (GE_EXPR, boolean_type_node, width,
-		       convert (TREE_TYPE (arg2), num_bits)));
+  cond = fold (build2 (GE_EXPR, boolean_type_node, width, num_bits));
 
   se->expr = fold (build3 (COND_EXPR, type, cond,
-			   convert (type, integer_zero_node),
-			   tmp));
+			   convert (type, integer_zero_node), tmp));
 }
 
 /* Circular shift.  AKA rotate or barrel shift.  */

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