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] Run simplify_relational_operation_1 for VOIDmode comparisons


The function simplify_relational_operation_1 should only be run if we
are dealing with a real comparison i.e. the mode of the comparison is
non-CC mode.  In addition to checking this
simplify_relational_operation will return without calling
simplify_relational_operation_1 if the mode of the comparison is
VOIDmode.  Note that this is the mode of the comparison expression and
not the mode in which the comparison is performed as that is always
the mode the operands.

Richard Sandiford has recently changed MIPS to expand conditional
branches with setting the mode of the comparison to VOIDmode.  This is
the expected form according to rtl.texi:

  The mode of the comparison operation is independent of the mode
  of the data being compared.  If the comparison operation is being tested
  (e.g., the first operand of an @code{if_then_else}), the mode must be
  @code{VOIDmode}.

But now, since the mode is VOID we don't run
simplify_relational_operation_1 on comparisons inside IF_THEN_ELSE
expressions and in turn miss optimizations like this:

  (if_then_else (eq (plus:SI (reg:SI 4) -1) -1) ...) 
  -> (if_then_else (eq (reg:SI 4) 0) ...) 

The C testcase is:

  void s (int n)  
  {  
    if (n--)  
      f (n);  
  }  

It seems the VOIDmode-check was added during the clean-up by Paolo
Bonzini in http://gcc.gnu.org/ml/gcc-patches/2004-04/msg01840.html.
Maybe he or someone else can explain why it is needed and what I am
missing.  Perhaps it was meant to check cmp_mode which is the mode of
the operands of the comparison?

Anyway, the patch below removes the check and lets
simplify_relational_operation_1 simplify comparison inside an
IF_THEN_ELSE.

I also tried the patch with x86_64-unknown-linux-gnu and it is a
consistent win on GCC preprocessed files (overall 77 testb
instructions get removed).  The typical change is:

        setne   %dl
-       testb   %dl, %dl
        jne     .L302

or in RTL:

  (if_then_else (eq (ne:QI (reg:CCZ 17) (const_int 0)) (const_int 0)) ...)
  -> (if_then_else (eq (reg:CCZ 17) (const_int 0)) ...)

I tested the patch on mipsisa64-elf and boostrapped and tested on
x86_64-unknown-linux-gnu.

Comments?  OK to apply?

Adam

	* simplify-rtx.c (simplify_relational_operation): Call
	simplify_relational_operation_1 even if mode is VOIDmode.

Index: simplify-rtx.c
===================================================================
--- simplify-rtx.c	(revision 112199)
+++ simplify-rtx.c	(working copy)
@@ -3517,8 +3517,7 @@ simplify_relational_operation (enum rtx_
     return simplify_relational_operation (code, mode, VOIDmode,
 				          XEXP (op0, 0), XEXP (op0, 1));
 
-  if (mode == VOIDmode
-      || GET_MODE_CLASS (cmp_mode) == MODE_CC
+  if (GET_MODE_CLASS (cmp_mode) == MODE_CC
       || CC0_P (op0))
     return NULL_RTX;
 


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