Bug 18002 - [3.4 Regression] 'while' loop performace regression on avr target
Summary: [3.4 Regression] 'while' loop performace regression on avr target
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.3
: P2 minor
Target Milestone: 3.4.4
Assignee: Roger Sayle
URL:
Keywords: missed-optimization, patch
Depends on:
Blocks:
 
Reported: 2004-10-14 19:48 UTC by berndtrog
Modified: 2004-12-14 02:08 UTC (History)
2 users (show)

See Also:
Host:
Target: avr-elf
Build:
Known to work: 3.3.3 4.0.0
Known to fail: 3.4.0
Last reconfirmed: 2004-10-14 20:04:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description berndtrog 2004-10-14 19:48:51 UTC
Hello,
when I compile(avr-gcc -c -Os -mmcu=atmega8 test.c) this code:

int main (void)
{
 while (((*(volatile unsigned char *)((0x0B) + 0x20)) & (1<<5)) == 0) {
  ;
 }

 return (0);
}

with gcc 3.3.1 I get this asm loop:

   8:   5d 9b           sbis    0x0b, 5 ; 11
   a:   fe cf           rjmp    .-4             ; 0x8


with gcc 3.4.2 or 4.0.0 I get this:

   8:   41 e0           ldi     r20, 0x01       ; 1
   a:   50 e0           ldi     r21, 0x00       ; 0 
   c:   8b b1           in      r24, 0x0b       ; 11
   e:   99 27           eor     r25, r25
  10:   25 e0           ldi     r18, 0x05       ; 5
  12:   96 95           lsr     r25
  14:   87 95           ror     r24
  16:   2a 95           dec     r18
  18:   e1 f7           brne    .-8             ; 0x12
  1a:   84 27           eor     r24, r20
  1c:   95 27           eor     r25, r21
  1e:   9c 01           movw    r18, r24
  20:   21 70           andi    r18, 0x01       ; 1
  22:   30 70           andi    r19, 0x00       ; 0
  24:   80 fd           sbrc    r24, 0
  26:   f2 cf           rjmp    .-28            ; 0xc
Comment 1 Andrew Pinski 2004-10-14 20:04:00 UTC
Actually this is also a regression on PPC:
3.3:
_main:
        li r2,43
L2:
        lbz r3,0(r2)
        andi. r9,r3,32
        beq+ cr0,L2
        li r3,0
        blr

4.0.0:
L3:
        lbz r0,0(r2)
        xori r0,r0,32
        andi. r9,r0,32
        bne+ cr0,L3
        li r3,0
        blr
Comment 2 David Edelsohn 2004-10-15 20:16:28 UTC
Proposed patch:
http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01299.html
Comment 3 GCC Commits 2004-10-18 18:47:42 UTC
Subject: Bug 18002

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	dje@gcc.gnu.org	2004-10-18 18:47:40

Modified files:
	gcc            : ChangeLog 

Log message:
	Note PR rtl-optimization/18002.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5931&r2=2.5932

Comment 4 Andrew Pinski 2004-10-25 21:42:04 UTC
Oh, it looks like the powerpc bug was different from the avr one and for the avr bug it looks like a 
target problem and nothing else, the rtl looks small.
Comment 5 Mark Mitchell 2004-11-01 00:44:46 UTC
Postponed until GCC 3.4.4.
Comment 6 Giovanni Bajo 2004-12-09 12:50:14 UTC
Proposed patch:
http://gcc.gnu.org/ml/gcc-patches/2004-12/msg00655.html
Comment 7 GCC Commits 2004-12-11 01:49:19 UTC
Subject: Bug 18002

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-12-11 01:49:06

Modified files:
	gcc            : ChangeLog dojump.c 

Log message:
	PR target/18002
	PR middle-end/18424
	* dojump.c (do_jump): When attempting to reverse the effects of
	fold_single_bit_test, we need to STRIP_NOPS and narrowing type
	conversions, and handle BIT_XOR_EXPR that's used to invert the
	sense of the single bit test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6778&r2=2.6779
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dojump.c.diff?cvsroot=gcc&r1=1.32&r2=1.33

Comment 8 Andrew Pinski 2004-12-11 07:41:21 UTC
Fixed on the mainline at least.
Comment 9 GCC Commits 2004-12-14 01:47:45 UTC
Subject: Bug 18002

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	sayle@gcc.gnu.org	2004-12-14 01:47:35

Modified files:
	gcc            : ChangeLog dojump.c Makefile.in 

Log message:
	PR target/18002
	PR middle-end/18424
	Backport from mainline
	
	2004-03-20  Richard Sandiford  <rsandifo@redhat.com>
	* Makefile.in (dojump.o): Depend on $(GGC_H) and dojump.h.
	(GTFILES): Add $(srcdir)/dojump.h.
	(gt-dojump.h): New dependency.
	* dojump.c (and_reg, and_test, shift_test): New static variables.
	(prefer_and_bit_test): New function.
	(do_jump): Use it to choose between (X & (1 << C)) and (X >> C) & 1.
	
	2004-03-21  Andrew Pinski  <pinskia@gcc.gnu.org>
	* dojump.c (prefer_and_bit_test): Fix which part of
	the and_test is replaced.
	
	2004-12-10  Roger Sayle  <roger@eyesopen.com>
	* dojump.c (do_jump): When attempting to reverse the effects of
	fold_single_bit_test, we need to STRIP_NOPS and narrowing type
	conversions, and handle BIT_XOR_EXPR that's used to invert the
	sense of the single bit test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.730&r2=2.2326.2.731
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dojump.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.9.4.1&r2=1.9.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/Makefile.in.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.1223.2.20&r2=1.1223.2.21

Comment 10 Andrew Pinski 2004-12-14 02:08:37 UTC
Fixed.