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: add new transformations in cse


X+(-Y) ==> X-Y
(-X)+Y ==> Y-X
X-(-Y) ==> X+Y
I believe all these are IEEE-compliant.

2001-12-18  Dale Johannesen  <dalej@apple.com>

          * cse.c (fold_rtx):  Add transformations for
          (X+(-Y)), ((-Y)+X), (X-(-Y))

Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.214
diff -u -d -b -w -c -3 -p -r1.214 cse.c
cvs server: conflicting specifications of output style
*** cse.c       2001/11/28 09:47:23     1.214
--- cse.c       2001/12/18 22:35:21
*************** fold_rtx (x, insn)
*** 3537,3542 ****
--- 3537,3566 ----
         return fold_rtx (copy_rtx (XEXP (new, 0)), insn);
         break;

+     case PLUS:
+       /* If we have (PLUS X Y), see if X is known to be (NEG Z).
+        If so, this simplifies to (MINUS Y Z).  */
+       new = lookup_as_function (XEXP (x, 0), NEG);
+       if (new)
+       return fold_rtx (gen_rtx_MINUS (mode, XEXP (x, 1),
+                           copy_rtx (XEXP (new, 0))), insn);
+       /* If we have (PLUS X Y), see if Y is known to be (NEG Z).
+        If so, this simplifies to (MINUS X Z).  */
+       new = lookup_as_function (XEXP (x, 1), NEG);
+       if (new)
+       return fold_rtx (gen_rtx_MINUS (mode, XEXP (x, 0),
+                           copy_rtx (XEXP (new, 0))), insn);
+       break;
+
+     case MINUS:
+       /* If we have (MINUS X Y), see if Y is known to be (NEG Z).
+        If so, this simplifies to (PLUS X Z).  */
+       new = lookup_as_function (XEXP (x, 1), NEG);
+       if (new)
+       return fold_rtx (gen_rtx_PLUS (mode, XEXP (x, 0),
+                           copy_rtx (XEXP (new, 0))), insn);
+       break;
+
       case MEM:
         /* If we are not actually processing an insn, don't try to find the
          best address.  Not only don't we care, but we could modify the


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