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] Simplify (cond (compare x y) 0) into (cond x y)



This innocent looking patch simplifies RTL of the form
(cond (COMPARE x y) 0) into the equivalent (cond x y) where cond
is one of GCC's RTL comparison codes (e.g. EQ, NE, GT, etc...).
This type of RTX is often generated when substituting the values
of condition code registers into conditional jump instructions.
>From my understanding of GCC internals this should always be safe,
but I'd very much like to see it on mainline on its own to convince
myself that it won't cause problems on obscure targets.

I've done a complete "make bootstrap" and "make -k check" on both
i686-pc-linux-gnu and alphaev67-dec-osf5.1 (all languages except
Ada) with no new regressions.  I've also confirmed that it does
what its supposed to whilst developing another patch.

Does this look safe?  simplify_relational_operation uses the same
idiom but only for simplifications with known constant operands
"x" and "y".  Ok for mainline?



2002-05-18  Roger Sayle  <roger@eyesopen.com>

	* simplify-rtx.c (simplify_gen_relational): Simplify the RTX
	(cond (compare x y) 0) into the equivalent (cond x y).


Index: simplify-rtx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/simplify-rtx.c,v
retrieving revision 1.103
diff -c -3 -p -r1.103 simplify-rtx.c
*** simplify-rtx.c	9 May 2002 12:02:28 -0000	1.103
--- simplify-rtx.c	18 May 2002 03:09:37 -0000
*************** simplify_gen_relational (code, mode, cmp
*** 232,237 ****
--- 232,241 ----
    if ((tem = simplify_relational_operation (code, cmp_mode, op0, op1)) != 0)
      return tem;

+   /* If op0 is a compare, extract the comparison arguments from it.  */
+   if (GET_CODE (op0) == COMPARE && op1 == const0_rtx)
+     op1 = XEXP (op0, 1), op0 = XEXP (op0, 0);
+
    /* Put complex operands first and constants second.  */
    if (swap_commutative_operands_p (op0, op1))
      tem = op0, op0 = op1, op1 = tem, code = swap_condition (code);

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]