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]

Implementing neg_optab using subtraction from zero


There seems to be a bit of inconsistency in the way negation and subtractions
from constants are handled.  If a backend doesn't define negMM for some
integer mode MM, expand_unop will always use a library call instead.
On other other hand, expand_binop will try to open-code subMM using
word-mode subtractions.

I'd like to remove the 32-bit negdi pattern from the MIPS port (patch to
follow shortly), but doing so will cause 32-bit code to use __negdi()
instead.  The patch below allows it to continue using inline negation
(in fact, it'll have the same four instructions as it does now).

Tested on mips64vrel-elf.  OK to install?

Richard


	* optabs.c (expand_unop): Try implementing negation using subtraction
	from zero.

Index: optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.221
diff -c -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.221 optabs.c
*** optabs.c	7 May 2004 05:38:14 -0000	1.221
--- optabs.c	15 May 2004 12:57:51 -0000
*************** expand_unop (enum machine_mode mode, opt
*** 2737,2742 ****
--- 2737,2751 ----
  	return temp;
      }
  
+   /* If there is no negation pattern, try subtracting from zero.  */
+   if (unoptab == neg_optab && class == MODE_INT)
+     {
+       temp = expand_binop (mode, sub_optab, CONST0_RTX (mode), op0,
+                            target, unsignedp, OPTAB_DIRECT);
+       if (temp)
+ 	return temp;
+     }
+ 
   try_libcall:
    /* Now try a library call in this mode.  */
    if (unoptab->handlers[(int) mode].libfunc)


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