public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14483] New: More aggressive compare insn elimination
@ 2004-03-08 16:48 kazu at cs dot umass dot edu
  2004-03-08 16:51 ` [Bug optimization/14483] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-03-08 16:48 UTC (permalink / raw)
  To: gcc-bugs

Consider:

void bar_0 (void);
void bar_1 (void);

void
foo (int a)
{
  if (a == 1)
    goto L0;
  if (a == 0)
    goto L1;
  return;

 L0:
  bar_0 ();
  return;

 L1:
  bar_1 ();
  return;
}

./cc1 -O2 -fomit-frame-pointer generates

foo:
	movl	4(%esp), %eax
	cmpl	$1, %eax
	je	.L2
	testl	%eax, %eax      <- sort of redundant
	je	.L4
	ret
	.p2align 2,,3
.L4:
	jmp	bar_1
	.p2align 2,,3
.L2:
	jmp	bar_0

At point where "testl" is, we still have the result of the last cmpl.
So we could do:

foo:
	movl	4(%esp), %eax
	cmpl	$1, %eax
	je	.L2
	jb	.L4          <- Notice, no "testl"!
	ret
	.p2align 2,,3
.L4:
	jmp	bar_1
	.p2align 2,,3
.L2:
	jmp	bar_0

-- 
           Summary: More aggressive compare insn elimination
           Product: gcc
           Version: tree-ssa
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14483


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug optimization/14483] More aggressive compare insn elimination
  2004-03-08 16:48 [Bug optimization/14483] New: More aggressive compare insn elimination kazu at cs dot umass dot edu
@ 2004-03-08 16:51 ` pinskia at gcc dot gnu dot org
  2004-03-08 19:51 ` kazu at cs dot umass dot edu
  2005-01-31 14:28 ` [Bug rtl-optimization/14483] " kazu at cs dot umass dot edu
  2 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-03-08 16:51 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-03-08 16:51 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |pessimizes-code
      Known to fail|                            |2.95.3 3.5.0 3.0.4 3.2.3
   Last reconfirmed|0000-00-00 00:00:00         |2004-03-08 16:51:27
               date|                            |
            Version|tree-ssa                    |3.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14483


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug optimization/14483] More aggressive compare insn elimination
  2004-03-08 16:48 [Bug optimization/14483] New: More aggressive compare insn elimination kazu at cs dot umass dot edu
  2004-03-08 16:51 ` [Bug optimization/14483] " pinskia at gcc dot gnu dot org
@ 2004-03-08 19:51 ` kazu at cs dot umass dot edu
  2005-01-31 14:28 ` [Bug rtl-optimization/14483] " kazu at cs dot umass dot edu
  2 siblings, 0 replies; 5+ messages in thread
From: kazu at cs dot umass dot edu @ 2004-03-08 19:51 UTC (permalink / raw)
  To: gcc-bugs


------- 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/14483] More aggressive compare insn elimination
  2004-03-08 16:48 [Bug optimization/14483] New: More aggressive compare insn elimination kazu at cs dot umass dot edu
  2004-03-08 16:51 ` [Bug optimization/14483] " pinskia at gcc dot gnu dot org
  2004-03-08 19:51 ` kazu at cs dot umass dot edu
@ 2005-01-31 14:28 ` kazu at cs dot umass dot edu
  2 siblings, 0 replies; 5+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-01-31 14:28 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From kazu at cs dot umass dot edu  2005-01-31 14:28 -------
*** Bug 19702 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yuri at tsoft dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14483


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug rtl-optimization/14483] More aggressive compare insn elimination
       [not found] <bug-14483-4@http.gcc.gnu.org/bugzilla/>
@ 2012-10-25 23:36 ` steven at gcc dot gnu.org
  0 siblings, 0 replies; 5+ messages in thread
From: steven at gcc dot gnu.org @ 2012-10-25 23:36 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14483

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.8.0

--- Comment #4 from Steven Bosscher <steven at gcc dot gnu.org> 2012-10-25 23:36:13 UTC ---
(In reply to comment #2)
> 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.

This is not a problem anymore since the DF merge. Liveness is now
available (and used) in all CSE passes.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-25 23:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-08 16:48 [Bug optimization/14483] New: More aggressive compare insn elimination kazu at cs dot umass dot edu
2004-03-08 16:51 ` [Bug optimization/14483] " pinskia at gcc dot gnu dot org
2004-03-08 19:51 ` kazu at cs dot umass dot edu
2005-01-31 14:28 ` [Bug rtl-optimization/14483] " kazu at cs dot umass dot edu
     [not found] <bug-14483-4@http.gcc.gnu.org/bugzilla/>
2012-10-25 23:36 ` steven at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).