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]

[PATCH] Extracting components of complex constants (take 2)


This patch is a revision of my earlier complex part extraction patch:
http://gcc.gnu.org/ml/gcc-patches/2003-05/msg02147.html

Richard Sandiford suggested that I minimize the duplicated code in
the original patch by factoring it into a separate function.  This
is a borderline case, the patch below is larger than the original,
but the reduced risk of updating one copy of the logic and not the
other makes this improvement worthwhile.

The following patch has been retested on i686-pc-linux-gnu with a
complete "make bootstrap", all languages except treelang, and
regression tested with a top-level "make -k check" with no new
failures.

Ok for mainline?


2003-05-26  Roger Sayle  <roger@eyesopen.com>

	* emit-rtl.c (gen_complex_constant_part): New function for getting
	the constant real or imaginary part of a complex constant.
	(gen_realpart): Use it.
	(gen_imagpart): Likewise.


Index: emit-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/emit-rtl.c,v
retrieving revision 1.325
diff -c -3 -p -r1.325 emit-rtl.c
*** emit-rtl.c	17 May 2003 22:21:30 -0000	1.325
--- emit-rtl.c	26 May 2003 12:38:08 -0000
*************** static int reg_attrs_htab_eq
*** 202,207 ****
--- 202,209 ----
  static reg_attrs *get_reg_attrs		PARAMS ((tree, int));
  static tree component_ref_for_mem_expr	PARAMS ((tree));
  static rtx gen_const_vector_0		PARAMS ((enum machine_mode));
+ static rtx gen_complex_constant_part	PARAMS ((enum machine_mode,
+ 						 rtx, int));

  /* Probability of the conditional branch currently proceeded by try_split.
     Set to -1 otherwise.  */
*************** gen_lowpart_common (mode, x)
*** 1294,1299 ****
--- 1296,1330 ----
    return 0;
  }

+ /* Return the constant real or imaginary part (which has mode MODE)
+    of a complex value X.  The IMAGPART_P argument determines whether
+    the real or complex component should be returned.  This function
+    returns NULL_RTX if the component isn't a constant.  */
+
+ static rtx
+ gen_complex_constant_part (mode, x, imagpart_p)
+      enum machine_mode mode;
+      rtx x;
+      int imagpart_p;
+ {
+   tree decl, part;
+
+   if (GET_CODE (x) == MEM
+       && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
+       && TREE_CONSTANT_POOL_ADDRESS_P (XEXP (x, 0)))
+     {
+       decl = SYMBOL_REF_DECL (XEXP (x, 0));
+       if (decl != NULL_TREE && TREE_CODE (decl) == COMPLEX_CST)
+ 	{
+ 	  part = imagpart_p ? TREE_IMAGPART (decl) : TREE_REALPART (decl);
+ 	  if (TREE_CODE (part) == REAL_CST
+ 	      || TREE_CODE (part) == INTEGER_CST)
+ 	    return expand_expr (part, NULL_RTX, mode, 0);
+ 	}
+     }
+   return NULL_RTX;
+ }
+
  /* Return the real part (which has mode MODE) of a complex value X.
     This always comes at the low address in memory.  */

*************** gen_realpart (mode, x)
*** 1302,1307 ****
--- 1333,1345 ----
       enum machine_mode mode;
       rtx x;
  {
+   rtx part;
+
+   /* Handle complex constants.  */
+   part = gen_complex_constant_part (mode, x, 0);
+   if (part != NULL_RTX)
+     return part;
+
    if (WORDS_BIG_ENDIAN
        && GET_MODE_BITSIZE (mode) < BITS_PER_WORD
        && REG_P (x)
*************** gen_imagpart (mode, x)
*** 1322,1327 ****
--- 1360,1372 ----
       enum machine_mode mode;
       rtx x;
  {
+   rtx part;
+
+   /* Handle complex constants.  */
+   part = gen_complex_constant_part (mode, x, 1);
+   if (part != NULL_RTX)
+     return part;
+
    if (WORDS_BIG_ENDIAN)
      return gen_lowpart (mode, x);
    else if (! WORDS_BIG_ENDIAN

Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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