This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/14483] More aggressive compare insn elimination
- From: "kazu at cs dot umass dot edu" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 8 Mar 2004 19:51:21 -0000
- Subject: [Bug optimization/14483] More aggressive compare insn elimination
- References: <20040308164756.14483.kazu@cs.umass.edu>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From kazu at cs dot umass dot edu 2004-03-08 19:51 -------
I created a simple patch to *detect* where the proposed optimization
would trigger.
Testing with a recent version of GCC shows this optimization would occur
27 times on all C source files directly under gcc/.
Of those, 25 of them have "cmp $1" followed by "testl".
The rest have "cmp $32" followed by "cmp $31" used to
determine LE (signed less than or equal to).
(That is, we can omit "cmp $31" and use LT instead).
The problem with extending cse_condition_code_reg() in cse.c is that
we have to determine the result of "testl", (reg 17) dies at the conditional
jump insn, but cse_condition_code_reg() is run before the flow analysis.
So we don't have liveness information. If this is to be implemented,
we may have to do this after the combine or something.
Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.229.2.31
diff -u -r1.229.2.31 cse.c
--- cse.c 5 Mar 2004 23:48:13 -0000 1.229.2.31
+++ cse.c 8 Mar 2004 19:36:23 -0000
@@ -7711,6 +7711,30 @@
&& (can_change_mode || comp_mode == mode))
found = true;
}
+ else if (GET_CODE (cc_src) == COMPARE
+ && GET_CODE (SET_SRC (set)) == COMPARE
+ && rtx_equal_p (XEXP (cc_src, 0),
+ XEXP (SET_SRC (set), 0))
+ && GET_CODE (XEXP (cc_src, 1)) == CONST_INT
+ && GET_CODE (XEXP (SET_SRC (set), 1)) == CONST_INT
+ && (INTVAL (XEXP (cc_src, 1))
+ == INTVAL (XEXP (SET_SRC (set), 1)) + 1)
+ && GET_CODE (BB_END (e->dest)) == JUMP_INSN)
+ {
+ rtx old_set = single_set (BB_END (e->dest));
+
+ if (old_set
+ && SET_DEST (old_set) == pc_rtx
+ && GET_CODE (SET_SRC (old_set)) == IF_THEN_ELSE)
+ {
+ rtx old_if_then_else = SET_SRC (old_set);
+ if (GET_CODE (XEXP (old_if_then_else, 0)) == LE
+ || GET_CODE (XEXP (old_if_then_else, 0)) == LEU
+ || (GET_CODE (XEXP (old_if_then_else, 0)) == EQ
+ && XEXP (SET_SRC (set), 1) == const0_rtx))
+ debug_rtx (insn);
+ }
+ }
if (found)
{
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14483