Debian Bug report logs - #75773
[PR optimization/3507]: appalling optimisation with sub/cmp on i386

version graph

Package: gcc-4.6; Maintainer for gcc-4.6 is Debian GCC Maintainers <debian-gcc@lists.debian.org>; Source for gcc-4.6 is src:gcc-4.6.

Reported by: <herbert@gondor.apana.org.au>

Date: Sat, 28 Oct 2000 06:18:02 UTC

Severity: wishlist

Tags: upstream

Merged with 107123

Found in version gcc-4.6/4.6.3-4

Forwarded to http://gcc.gnu.org/PR3507

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Debian GCC maintainers <gcc@packages.debian.org>:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to <herbert@gondor.apana.org.au>:
New Bug report received and forwarded. Copy sent to Debian GCC maintainers <gcc@packages.debian.org>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: <herbert@gondor.apana.org.au>
To: submit@bugs.debian.org
Subject: gcc: appalling optimisation with sub/cmp on i386
Date: Sat, 28 Oct 2000 17:10:57 +1100
Package: gcc
Version: 1:2.95.2-16
Severity: normal

For the file

unsigned long foo(unsigned long a, unsigned long b) {
	unsigned long c = a - b;

	if (a < b) {
		c += 100;
	}

	return c;
}

gcc -O2 -S generates

	.file	"subcmp.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl foo
	.type	 foo,@function
foo:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%ecx
	movl 12(%ebp),%eax
	movl %ecx,%edx
	subl %eax,%edx
	cmpl %eax,%ecx
	jae .L3
	addl $100,%edx
.L3:
	movl %edx,%eax
	leave
	ret
.Lfe1:
	.size	 foo,.Lfe1-foo
	.ident	"GCC: (GNU) 2.95.2 20000220 (Debian GNU/Linux)"

The cmpl after the subl is unnecessary.

gcc-ss 2.97-0.1 generates pretty much the same code.

-- System Information
Debian Release: woody
Kernel Version: Linux gondor 2.2.17 #1 Mon Sep 11 22:22:16 EST 2000 i586 unknown

Versions of the packages gcc depends on:
ii  binutils            2.10.0.27-0.cvs2000 The GNU assembler, linker and binary utilities.
ii  cpp                 2.95.2-16           The GNU C preprocessor.
ii  libc6               2.1.95-1            GNU C Library: Shared libraries and Timezone data



Severity set to `wishlist'. Request was from Philip Blundell <philb@gnu.org> to control@bugs.debian.org. Full text and rfc822 format available.

Acknowledgement sent to gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #10 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: gcc-gnats@gcc.gnu.org
To: 75773-quiet@bugs.debian.org
Subject: Re: optimization/3507: appalling optimisation with sub/cmp on i386
Date: 1 Jul 2001 16:16:00 -0000
Thank you very much for your problem report.
It has the internal identification `optimization/3507'.
The individual assigned to look at your
report is: unassigned. 

>Category:       optimization
>Responsible:    unassigned
>Synopsis:       appalling optimisation with sub/cmp on i386
>Arrival-Date:   Sun Jul 01 09:16:00 PDT 2001



Noted your statement that Bug has been forwarded to gcc-gnats@gcc.gnu.org. Request was from Matthias Klose <doko@klose.in-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Changed Bug title. Request was from Matthias Klose <doko@klose.in-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Acknowledgement sent to doko@debian.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #17 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: Matthias Klose <doko@klose.in-berlin.de>
To: control@bugs.debian.org
Cc: 75773-quiet@bugs.debian.org
Subject: gcc: submitted Debian report #75773 to gcc-gnats as PR 3507
Date: Sun, 01 Jul 2001 19:03:19 +0200
# submitted Debian report #75773 to gcc-gnats as PR 3507
# http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=3507&database=gcc

forwarded 75773 gcc-gnats@gcc.gnu.org
retitle 75773 [PR optimization/3507]: appalling optimisation with sub/cmp on i386
thanks



Information forwarded to gcc-defaults@packages.qa.debian.org:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to rth@gcc.gnu.org, 75773-quiet@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, herbert@gondor.apana.org.au, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org:
Extra info received and filed, but not forwarded. Copy sent to gcc-defaults@packages.qa.debian.org. Full text and rfc822 format available.

Message #22 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: rth@gcc.gnu.org
To: 75773-quiet@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, herbert@gondor.apana.org.au, nobody@gcc.gnu.org
Subject: Re: optimization/3507: appalling optimisation with sub/cmp on i386
Date: 2 Apr 2002 10:36:07 -0000
Synopsis: appalling optimisation with sub/cmp on i386

State-Changed-From-To: open->analyzed
State-Changed-By: rth
State-Changed-When: Tue Apr  2 02:36:06 2002
State-Changed-Why:
       (set (reg/v:SI 61)
            (minus:SI (reg/v:SI 59) (reg/v:SI 60)))
    
    and
    
       (set (reg:CC 17 flags)
            (compare:CC (reg/v:SI 59) (reg/v:SI 60))) 
    
    are not LOG_LINK related, because they share no common
    destination, so combine doesn't merge them.  But after
    reload, they don't have the same arguments, so we can't
    peephole them there either.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=3507



Information forwarded to gcc-defaults@packages.qa.debian.org:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to neil@gcc.gnu.org, 75773-quiet@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org:
Extra info received and filed, but not forwarded. Copy sent to gcc-defaults@packages.qa.debian.org. Full text and rfc822 format available.

Message #27 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: neil@gcc.gnu.org
To: 75773-quiet@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: pending/6132: Bug#75773: Info received and FILED only
Date: 3 Apr 2002 11:22:56 -0000
Synopsis: Bug#75773: Info received and FILED only

State-Changed-From-To: open->closed
State-Changed-By: neil
State-Changed-When: Wed Apr  3 03:22:54 2002
State-Changed-Why:
    This is tedious - can you stop Debbugs replying to GNATS?
    They get themselves in a mail loop.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6132



Merged 75773 107123. Request was from Matthias Klose <doko@cs.tu-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to gcc-defaults@packages.qa.debian.org:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to bangerth@dealii.org, 75773-quiet@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org:
Extra info received and filed, but not forwarded. Copy sent to gcc-defaults@packages.qa.debian.org. Full text and rfc822 format available.

Message #34 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: bangerth@dealii.org
To: 75773-quiet@bugs.debian.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org
Subject: Re: pending/6152: Bug#75773: Info received and FILED only
Date: 18 Dec 2002 15:52:09 -0000
Synopsis: Bug#75773: Info received and FILED only

State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Wed Dec 18 07:52:08 2002
State-Changed-Why:
    Mail picked up accidentially.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6152



Merged 75773 107123. Request was from Matthias Klose <doko@cs.tu-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Forwarded-to-address changed from gcc-gnats@gcc.gnu.org to http://gcc.gnu.org/PR3507. Request was from Matthias Klose <doko@cs.tu-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Forwarded-to-address changed from http://gcc.gnu.org/PR3507 to http://gcc.gnu.org/PR3507. Request was from Matthias Klose <doko@cs.tu-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Tags added: upstream Request was from Matthias Klose <doko@cs.tu-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Tags added: upstream Request was from Matthias Klose <doko@cs.tu-berlin.de> to control@bugs.debian.org. Full text and rfc822 format available.

Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #49 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "pinskia at physics dot uc dot edu" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug optimization/3507] appalling optimisation with sub/cmp on i386
Date: 3 Aug 2003 17:59:19 -0000
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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


pinskia at physics dot uc dot edu changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 GCC target triplet|i386-linux                  |i386-linux, powerpc-*-*
   Last reconfirmed|0000-00-00 00:00:00         |2003-08-03 17:59:19
               date|                            |


------- Additional Comments From pinskia at physics dot uc dot edu  2003-08-03 17:59 -------
It also happens on powerpc-apple-darwin6.6
Currently GCC produces:
_foo:
        cmplw cr0,r3,r4
        subf r3,r4,r3
        bgelr- cr0
        addi r3,r3,100
        blr
But GCC should be able to produce:
_foo:
        subf. r3,r4,r3
        bgelr- cr0
        addi r3,r3,100
        blr
Which is smaller (and faster on every thing except maybe 970 and Power4).



------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #54 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug optimization/3507] appalling optimisation with sub/cmp on i386
Date: 26 Dec 2003 03:30:03 -0000

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #59 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "kazu at cs dot umass dot edu" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug optimization/3507] appalling optimisation with sub/cmp on i386
Date: 4 Jan 2004 08:26:42 -0000
------- Additional Comments From kazu at cs dot umass dot edu  2004-01-04 08:26 -------
Replacing a < b with (long) c < 0 sounds like a CSE type of work
but does not quite fit in the current framework of replacing
expensive expressions with cheaper equivalents that are already available.
That is, nobody has computed (long) c < 0 before, so it's not available.



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kazu at cs dot umass dot edu


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Message #62 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "cyrille at chepelov dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug optimization/3507] appalling optimisation with sub/cmp on i386
Date: 3 Mar 2004 19:46:40 -0000
------- Additional Comments From cyrille at chepelov dot org  2004-03-03 19:46 -------
Observed on m68k-palmos (2.95.3+Debian boatload of patches), arm-palmos (3.2.2),
AVR (3.3, 20030512 prerelease, likely patched), and on i386 (3.3.3, mainline and
tree-ssa as of 20040302).

I suggest updating $SUMMARY and $TARGET accordingly.

Further testing (see attachement) show that opportunities can be missed even for
simple signed ints: bar() has the problem, while baz() and bat() use either cmp
or sub, but not both. Furthermore, baz() seems to show that the combine pass is
doing a good job of finding the right compare instruction when the primary
result of the subtraction is thrown away. Could it be possible that a simple and
systematic:

   (a < b)     ===>  (coerce_to_signed_type<>(a - b) < 0) 

replacement (done perhaps at the SSA level) would resolve this, without
incurring excessive costs?


-- 


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Message #65 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "cyrille at chepelov dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug optimization/3507] appalling optimisation with sub/cmp on i386
Date: 3 Mar 2004 19:52:34 -0000
------- Additional Comments From cyrille at chepelov dot org  2004-03-03 19:52 -------
Created an attachment (id=5856)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=5856&action=view)
a variant test (with signed ints instead of unsigned longs -- same problem)

bar() shows the same problem as the original poster

baz() shows a variant of bar(), which although not semantically identical,
shows on i386 that the RTL optimizer is able to use a cmp instruction anyway
(also on AVR, but NOT on ARM).

bat() is semantically identical to bar() (modulo possible data overflow), and
shows the kind of code which would be expected from compiling bar(). 

-- 


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Message #68 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "ian at wasabisystems dot com" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug optimization/3507] appalling optimisation with sub/cmp on i386
Date: 3 Mar 2004 20:13:43 -0000

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ian at wasabisystems dot com


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Message #71 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "steven at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on i386
Date: 23 Jan 2005 14:57:45 -0000
------- Additional Comments From steven at gcc dot gnu dot org  2005-01-23 14:57 -------
Still there as of 2005-01-23 

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2004-12-01 03:19:31         |2005-01-23 14:57:43
               date|                            |


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc. Full text and rfc822 format available.

Message #74 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "rth at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on i386
Date: 24 Jan 2005 02:06:45 -0000

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|rth at gcc dot gnu dot org  |


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Bug reassigned from package `gcc' to `gcc-4.0'. Request was from Falk Hueffner <falk@debian.org> to control@bugs.debian.org. Full text and rfc822 format available.

Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Message #79 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on i386
Date: 7 Dec 2005 03:44:55 -0000

-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-09-07 17:29:51         |2005-12-07 03:44:54
               date|                            |


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Message #82 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on i386
Date: 5 Mar 2006 03:13:08 -0000

-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-12-07 03:44:54         |2006-03-05 03:13:08
               date|                            |


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #87 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "eweddington at cso dot atmel dot com" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 23 Aug 2007 20:10:25 -0000

------- Comment #7 from eweddington at cso dot atmel dot com  2007-08-23 20:10 -------
Confirmed for AVR. GCC 4.2.1 for avr generates this:

foo:
/* prologue: frame size=0 */
        push r14
        push r15
        push r16
        push r17
/* prologue end (size=4) */
        movw r14,r22
        movw r16,r24
        sub r14,r18
        sbc r15,r19
        sbc r16,r20
        sbc r17,r21
        cp r22,r18
        cpc r23,r19
        cpc r24,r20
        cpc r25,r21
        brsh .L2
        ldi r24,lo8(100)
        ldi r25,hi8(100)
        ldi r26,hlo8(100)
        ldi r27,hhi8(100)
        add r14,r24
        adc r15,r25
        adc r16,r26
        adc r17,r27
.L2:
        movw r24,r16
        movw r22,r14
/* epilogue: frame size=0 */
        pop r17
        pop r16
        pop r15
        pop r14
        ret

Ideally it should be something like:

foo:
/* prologue: frame size=0 */
        sub r22,r18
        sbc r23,r19
        sbc r24,r20
        sbc r25,r21
        brcc .L2
        ldi r18,lo8(100)
        ldi r19,hi8(100)
        ldi r20,hlo8(100)
        ldi r21,hhi8(100)
        add r22,r18
        adc r23,r19
        adc r24,r20
        adc r25,r21
.L2:
/* epilogue: frame size=0 */
        ret

Which is less than half the number of instructions.

Changing summary and target fields


-- 

eweddington at cso dot atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 GCC target triplet|i386-linux, powerpc-*-*     |i386-linux, powerpc-*-*,
                   |                            |avr-*-*
   Last reconfirmed|2006-03-05 03:13:08         |2007-08-23 20:10:25
               date|                            |
            Summary|appalling optimisation with |appalling optimisation with
                   |sub/cmp on i386             |sub/cmp on multiple targets


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #92 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "eweddington at cso dot atmel dot com" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 23 Aug 2007 20:10:53 -0000

-- 

eweddington at cso dot atmel dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eweddington at cso dot atmel
                   |                            |dot com


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.



Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #97 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "rask at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 2 Nov 2007 14:17:53 -0000

-- 

rask at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rask at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-08-23 20:10:25         |2007-11-02 14:17:51
               date|                            |


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #102 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "rask at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 27 Nov 2007 18:04:32 -0000

------- Comment #8 from rask at gcc dot gnu dot org  2007-11-27 18:04 -------
Created an attachment (id=14647)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14647&action=view)
Patch to enhance cse.c

The attached patch can optimize this testcase:

void foo (int);

int bar2 (int a, int b)
{
  int c = a - b;
  if (a < b)
    {
      foo (c);
    }
  return c;
}

Before:
bar2:
        pushl   %ebx            # 33    *pushsi2        [length = 1]
        subl    $8, %esp        # 34    pro_epilogue_adjust_stack_1/1   [length
= 3]
        movl    16(%esp), %edx  # 2     *movsi_1/1      [length = 4]
        movl    20(%esp), %eax  # 3     *movsi_1/1      [length = 4]
        movl    %edx, %ebx      # 32    *movsi_1/1      [length = 2]
        subl    %eax, %ebx      # 7     *subsi_1/1      [length = 2]
        cmpl    %eax, %edx      # 8     *cmpsi_1_insn/1 [length = 2]
        jge     .L2             # 9     *jcc_1  [length = 2]
        movl    %ebx, (%esp)    # 11    *movsi_1/2      [length = 3]
        call    foo             # 12    *call_0 [length = 5]
.L2:
        movl    %ebx, %eax      # 19    *movsi_1/1      [length = 2]
        addl    $8, %esp        # 37    pro_epilogue_adjust_stack_1/1   [length
= 3]
        popl    %ebx            # 38    popsi1  [length = 1]
        ret                     # 39    return_internal [length = 1]

After:
bar2:
        pushl   %ebx            # 33    *pushsi2        [length = 1]
        subl    $8, %esp        # 34    pro_epilogue_adjust_stack_1/1   [length
= 3]
        movl    16(%esp), %eax  # 2     *movsi_1/1      [length = 4]
        movl    %eax, %ebx      # 32    *movsi_1/1      [length = 2]
        subl    20(%esp), %ebx  # 8     *subsi_2/2      [length = 4]
        jns     .L2             # 9     *jcc_1  [length = 2]
        movl    %ebx, (%esp)    # 11    *movsi_1/2      [length = 3]
        call    foo             # 12    *call_0 [length = 5]
.L2:
        movl    %ebx, %eax      # 19    *movsi_1/1      [length = 2]
        addl    $8, %esp        # 37    pro_epilogue_adjust_stack_1/1   [length
= 3]
        popl    %ebx            # 38    popsi1  [length = 1]
        ret             # 39    return_internal [length = 1]

One of the difficulties is that by the time the code gets to the cse1 pass, the
statement "c = a - b" might have been moved below the "a < b" test, making it
harder to optimize. The "bar2" testcase was crafted so this doesn't happen. But
given the need to potentially replace both the sub/cmp insn and the jump insn,
it would be better to move this optimization to combine.


-- 


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #107 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "rask at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 28 Nov 2007 18:01:18 -0000

------- Comment #9 from rask at gcc dot gnu dot org  2007-11-28 18:01 -------
Created an attachment (id=14657)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=14657&action=view)
Patch v2 to enhance cse.c

This patch also handles unsigned comparisons and thus optimizes the original
testcase too. Before:

foo:
        movl    4(%esp), %edx   # 2     *movsi_1/1      [length = 4]
        movl    8(%esp), %eax   # 3     *movsi_1/1      [length = 4]
        movl    %edx, %ecx      # 35    *movsi_1/1      [length = 2]
        subl    %eax, %ecx      # 7     *subsi_1/1      [length = 2]
        cmpl    %eax, %edx      # 8     *cmpsi_1_insn/1 [length = 2]
        jae     .L2             # 9     *jcc_1          [length = 2]
        addl    $100, %ecx      # 11    *addsi_1/1      [length = 3]
.L2:
        movl    %ecx, %eax      # 18    *movsi_1/1      [length = 2]
        ret                     # 38    return_internal [length = 1]

After:
foo:
        movl    4(%esp), %eax   # 2     *movsi_1/1      [length = 4]
        subl    8(%esp), %eax   # 8     *subsi3_cc_overflow/2   [length = 4]
        jae     .L2             # 9     *jcc_1          [length = 2]
        addl    $100, %eax      # 11    *addsi_1/1      [length = 3]
.L2:
        rep                     # 39    return_internal_long    [length = 1]
        ret

I was going to abandon this patch, but maybe it deserves a second chance. :-)


-- 

rask at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #14647|0                           |1
        is obsolete|                            |


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #112 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "steven at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 28 Nov 2007 22:02:46 -0000

------- Comment #10 from steven at gcc dot gnu dot org  2007-11-28 22:02 -------
> +  for (defs = DF_INSN_DEFS (insn);
> +       *defs && DF_REF_REGNO (*defs) != REGNO (x);
> +       defs++)
> +    ;

Are you aware of df_find_def() ?


> +	  if (minus_elt)
> +	      cmp = cse_find_comparison_use (dest, insn);

Formatting.


IMNSHO, computing DEF-USE chains for this niche optimization loses in the
cost/benefit trade-off.  The whole patch looks like a hack to me to
specifically deal with this particular bug report.  You could, of course, show
that this is actually a very important optimization...

I wonder if you can't just integrate this optimization in cse.c as-is by
recording an equivalence "a < b" == "signof(c)" when you process "a - b".

In any case, adding this optimization to cse.c is Just Wrong (tm).  I don't
understand why you didn't even try to optimize this in one of the tree
optimizers instead.  I thought it was clear GCC is trying to reduce its
dependency on RTL optimizations?


-- 


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #117 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "rask at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 29 Nov 2007 00:09:52 -0000

------- Comment #11 from rask at gcc dot gnu dot org  2007-11-29 00:09 -------
In reply to comment #10 from Steven Bosscher 2007-11-28 22:02:

> > +  for (defs = DF_INSN_DEFS (insn);
> > +       *defs && DF_REF_REGNO (*defs) != REGNO (x);
> > +       defs++)
> > +    ;

> Are you aware of df_find_def() ?

   Not until now, and it won't work either, because it uses rtx_equal_p() and
the mode of DF_REF_REG() doesn't match that of the REG rtx in the insn. See
also <URL:http://gcc.gnu.org/ml/gcc/2007-11/msg00719.html>.

> IMNSHO, computing DEF-USE chains for this niche optimization loses in the
> cost/benefit trade-off.

   The split of the comparison setter and the comparison user across two
insns with no link between them is an interesting case of poor
infrastructure. Most back ends can't emit the setter before they know what
the user looks like and therefore always emit the two back-to-back. At the
same time, several passes need to find one from the other but can't rely on
them to be back-to-back and because there's no link between them (except if
by DEF-USE/USE-DEF), they have to roll their own means of doing so.

   (So yes, it's been done without DEF-USE before and it can be done without
DEF-USE again.)

> I wonder if you can't just integrate this optimization in cse.c as-is by
> recording an equivalence "a < b" == "signof(c)" when you process "a - b".

   That doesn't catch the unsigned comparison. Actually, how would I even
know if it is unsigned or not?

> In any case, adding this optimization to cse.c is Just Wrong (tm).  I
> don't understand why you didn't even try to optimize this in one of the
> tree optimizers instead.  I thought it was clear GCC is trying to reduce
> its dependency on RTL optimizations?

   There's no way to optimize the signed case with -fwrapv (e.g. Java) at
the tree level, because we can't arrange for a - b to be computed in the
same instruction as a < b. At the RTL level, it is merely difficult. That
makes it less interesting to work on this optimization at the tree level.


-- 


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Information stored:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to gcc-bugzilla@gcc.gnu.org:
Extra info received and filed, but not forwarded. Full text and rfc822 format available.

Message #122 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "bonzini at gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: 29 Nov 2007 11:43:39 -0000

------- Comment #12 from bonzini at gnu dot org  2007-11-29 11:43 -------
I think this should use find_comparison_args.


-- 

bonzini at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bonzini at gnu dot org


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

------- You are receiving this mail because: -------
You reported the bug, or are watching the reporter.




Information forwarded to debian-bugs-dist@lists.debian.org, Debian GCC Maintainers <debian-gcc@lists.debian.org>:
Bug#75773; Package gcc-4.0. Full text and rfc822 format available.

Acknowledgement sent to Matthias Klose <doko@cs.tu-berlin.de>:
Extra info received and forwarded to list. Copy sent to Debian GCC Maintainers <debian-gcc@lists.debian.org>. Full text and rfc822 format available.

Message #127 received at 75773@bugs.debian.org (full text, mbox):

From: Matthias Klose <doko@cs.tu-berlin.de>
To: 75773-submitter@bugs.debian.org, 75773@bugs.debian.org
Subject: please recheck with gcc-4.3/g++-4.3/gcj-4.3 from unstable
Date: Wed, 30 Jan 2008 21:43:16 +0100 (MET)
This bug report was submitted for an older version of gcc/g++/gcj.
Please recheck with the current gcc-4.3/g++-4.3/gcj-4.3 packages
from unstable.




Message sent on to <herbert@gondor.apana.org.au>:
Bug#75773. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, unknown-package@qa.debian.org:
Bug#75773; Package gcc-4.0. (Wed, 02 May 2012 19:15:10 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Manuel A. Fernandez Montecelo" <manuel.montezelo@gmail.com>:
Extra info received and forwarded to list. Copy sent to unknown-package@qa.debian.org. (Wed, 02 May 2012 19:15:10 GMT) Full text and rfc822 format available.

Message #135 received at 75773@bugs.debian.org (full text, mbox):

From: "Manuel A. Fernandez Montecelo" <manuel.montezelo@gmail.com>
To: 75773@bugs.debian.org
Subject: Re: [PR optimization/3507]: appalling optimisation with sub/cmp on i386
Date: Wed, 2 May 2012 20:12:22 +0100
reassign 75773 gcc-4.6
found 75773 4.6.3-4
stop

Hi,

I could reproduce the bug when compiling with this 4.6.3-4 version
(the default in Debian unstable at this time), when using -m32 in
amd64:

---------------------------------------------------------------------
$ gcc -O2 -S -m32 test1.c -o test1.m32.s
$ cat test1.m32.s
        .file   "test1.c"
        .text
        .p2align 4,,15
        .globl  foo
        .type   foo, @function
foo:
.LFB0:
        .cfi_startproc
        movl    4(%esp), %ecx
        movl    8(%esp), %edx
        movl    %ecx, %eax
        subl    %edx, %eax
        cmpl    %edx, %ecx
        jae     .L2
        addl    $100, %eax
.L2:
        rep
        ret
        .cfi_endproc
.LFE0:
        .size   foo, .-foo
        .ident  "GCC: (Debian 4.6.3-4) 4.6.3"
        .section        .note.GNU-stack,"",@progbits
---------------------------------------------------------------------

Though surely not important, just for completion, with -m64 the result
is completely different:
---------------------------------------------------------------------
$ gcc -O2 -S -m64 test1.c -o test1.m64.s
$ cat test1.m64.s
        .file   "test1.c"
        .text
        .p2align 4,,15
        .globl  foo
        .type   foo, @function
foo:
.LFB0:
        .cfi_startproc
        movq    %rdi, %rax
        subq    %rsi, %rax
        cmpq    %rsi, %rdi
        leaq    100(%rax), %rdx
        cmovb   %rdx, %rax
        ret
        .cfi_endproc
.LFE0:
        .size   foo, .-foo
        .ident  "GCC: (Debian 4.6.3-4) 4.6.3"
        .section        .note.GNU-stack,"",@progbits
---------------------------------------------------------------------

Also confirmed with GCC 4.7.0, the only difference to the files above
is the line about the version of the compiler:
---------------------------------------------------------------------
$ gcc-4.7 --version | head -n 1
gcc-4.7 (Debian 4.7.0-6) 4.7.0

$ diff -U0 test1.{,gcc47-}m32.s
--- test1.m32.s 2012-05-02 20:05:55.908296453 +0100
+++ test1.gcc47-m32.s   2012-05-02 20:08:01.824292734 +0100
@@ -22 +22 @@
-       .ident  "GCC: (Debian 4.6.3-4) 4.6.3"
+       .ident  "GCC: (Debian 4.7.0-6) 4.7.0"

$ diff -U0 test1.{,gcc47-}m64.s
--- test1.m64.s 2012-05-02 20:06:20.652295721 +0100
+++ test1.gcc47-m64.s   2012-05-02 20:07:52.868292996 +0100
@@ -18 +18 @@
-       .ident  "GCC: (Debian 4.6.3-4) 4.6.3"
+       .ident  "GCC: (Debian 4.7.0-6) 4.7.0"
---------------------------------------------------------------------




Bug reassigned from package 'gcc-4.0' to 'gcc-4.6'. Request was from "Manuel A. Fernandez Montecelo" <manuel.montezelo@gmail.com> to control@bugs.debian.org. (Wed, 02 May 2012 19:15:12 GMT) Full text and rfc822 format available.

Marked as found in versions gcc-4.6/4.6.3-4. Request was from "Manuel A. Fernandez Montecelo" <manuel.montezelo@gmail.com> to control@bugs.debian.org. (Wed, 02 May 2012 19:15:12 GMT) Full text and rfc822 format available.

Information stored :
Bug#75773; Package gcc-4.6. (Tue, 10 Jul 2012 10:54:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to "daniel.santos at pobox dot com" <gcc-bugzilla@gcc.gnu.org>:
Extra info received and filed, but not forwarded. (Tue, 10 Jul 2012 10:54:05 GMT) Full text and rfc822 format available.

Message #144 received at 75773-quiet@bugs.debian.org (full text, mbox):

From: "daniel.santos at pobox dot com" <gcc-bugzilla@gcc.gnu.org>
To: 75773-quiet@bugs.debian.org
Subject: [Bug rtl-optimization/3507] appalling optimisation with sub/cmp on multiple targets
Date: Tue, 10 Jul 2012 10:23:08 +0000
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3507

Daniel Santos <daniel.santos at pobox dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.santos at pobox dot
                   |                            |com

--- Comment #13 from Daniel Santos <daniel.santos at pobox dot com> 2012-07-10 10:23:08 UTC ---
Well here's another test case for the same problem:

extern print_gt(void);
extern print_lt(void);
extern print_eq(void);

void cmp_and_branch(long a, long b)
{
    long diff = a - b;

    if (diff > 0) {
        print_gt();
    } else if (diff < 0) {
        print_lt();
    } else {
        print_eq();
    }
}

In this case, the result of the subtraction is directly used in the branch
code.  However, gcc -O2 -S still generates this output:

    .file    "gcc_cmp_and_branch_test2.c"
    .text
    .p2align 4,,15
    .globl    cmp_and_branch
    .type    cmp_and_branch, @function
cmp_and_branch:
.LFB0:
    .cfi_startproc
    subq    %rsi, %rdi
    cmpq    $0, %rdi
    jg    .L5
    jne    .L6
    jmp    print_eq
    .p2align 4,,10
    .p2align 3
.L5:
    jmp    print_gt
    .p2align 4,,10
    .p2align 3
.L6:
    jmp    print_lt
    .cfi_endproc
.LFE0:
    .size    cmp_and_branch, .-cmp_and_branch
    .ident    "GCC: (Gentoo 4.7.1) 4.7.1"
    .section    .note.GNU-stack,"",@progbits

I'm using Gentoo x86_64:

Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.7.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/portage/sys-devel/gcc-4.7.1/work/gcc-4.7.1/configure
--prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1
--includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include
--datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1
--mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/man
--infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/info
--with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4
--host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec
--disable-fixed-point --with-ppl --with-cloog --disable-ppl-version-check
--with-cloog-include=/usr/include/cloog-ppl --enable-lto --enable-nls
--without-included-gettext --with-system-zlib --enable-obsolete
--disable-werror --enable-secureplt --enable-multilib
--with-multilib-list=m32,m64 --enable-libmudflap --disable-libssp
--enable-libgomp
--with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/python
--enable-checking=release --enable-java-awt=gtk --enable-objc-gc
--enable-languages=c,c++,java,objc,obj-c++,fortran --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
--enable-targets=all --with-bugurl=http://bugs.gentoo.org/
--with-pkgversion='Gentoo 4.7.1'
Thread model: posix
gcc version 4.7.1 (Gentoo 4.7.1) 

I do hope this can be addressed sometime soon.  Thanks.

-- 
Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You reported the bug.




Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Wed Apr 16 14:19:33 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.