Bug 11181 - [3.3 only][avr-gcc] Optimization of "uchar/xor/and/single_bit" produced wrong code.
Summary: [3.3 only][avr-gcc] Optimization of "uchar/xor/and/single_bit" produced wrong...
Status: RESOLVED DUPLICATE of bug 11662
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 3.3.1
: P2 normal
Target Milestone: 3.3.2
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-06-13 03:10 UTC by Dmitry K.
Modified: 2003-08-03 16:19 UTC (History)
2 users (show)

See Also:
Host:
Target: avr-*-none
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-07-06 01:30:31


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry K. 2003-06-13 03:10:30 UTC
Optimization of next program produced infinite loop: 
 
	unsigned char f(void); 
 
	void foo(void) 
	{ 
	    while ( ((f() ^ 1) & 1) == 0 ) ; 
	} 
 
Result is (avr-gcc -W -Wall -O1 -S xor.c): 
 
        .file   "xor.c" 
        .arch avr2 
__SREG__ = 0x3f 
__SP_H__ = 0x3e 
__SP_L__ = 0x3d 
__tmp_reg__ = 0 
__zero_reg__ = 1 
        .global __do_copy_data 
        .global __do_clear_bss 
        .text 
.global foo 
        .type   foo, @function 
foo: 
/* prologue: frame size=0 */ 
        push r28 
/* prologue end (size=1) */ 
.L2: 
        rcall f 
        rjmp .L2 
/* epilogue: frame size=0 */ 
/* epilogue: noreturn */ 
/* epilogue end (size=0) */ 
/* function foo size 3 (2) */ 
        .size   foo, .-foo 
/* File "xor.c": code    3 = 0x0003 (   2), prologues   1, epilogues   0 */
Comment 1 Andrew Pinski 2003-07-06 01:30:31 UTC
I can confirm this on the mainline (20030706) but with -Os.
Comment 2 Christian Ehrhardt 2003-07-28 12:23:12 UTC
This appears to be a duplicate of 11662. Could you try the patch
attached to that report and see if that help?

     regards  Christian
Comment 3 Andrew Pinski 2003-07-28 16:20:57 UTC
It looks like the mainline (20030728) is still broken with -Os (but I do not read avr asm.):
.L2:
        rcall f
        ldi r25,lo8(1)
        eor r25,r24
        sbrs r25,0
        rjmp .L2
Could you say if that works (is rjmp unconditional jump?)?
Comment 4 Andrew Pinski 2003-07-28 16:27:02 UTC
It works on the mainline, I looked at the RTL at the last stage and it had:
(jump_insn 19 18 24 (set (pc)
        (if_then_else (eq (zero_extract:HI (reg:QI 25 r25 [42])
                    (const_int 1 [0x1])
                    (const_int 0 [0x0]))
                (const_int 0 [0x0]))
            (label_ref 9)
            (pc))) 97 {*sbrx_branch} (insn_list 13 (nil))
    (expr_list:REG_DEAD (reg:QI 25 r25 [42])
        (expr_list:REG_BR_PROB (const_int 8900 [0x22c4])
            (nil))))

So it worked.
I will test the patch to find out if it fixes the problem on 3.3.1.
Comment 5 Christian Ehrhardt 2003-07-28 16:42:56 UTC
Subject: Re:  [avr-gcc] Optimization of "uchar/xor/and/single_bit" produced wrong code.

On Mon, Jul 28, 2003 at 04:20:58PM -0000, pinskia at physics dot uc dot edu wrote:
> It looks like the mainline (20030728) is still broken with -Os
> (but I do not read avr asm.):

I've never seen an avr either ;-) But now gcc at least emmits an eor
after the call which is definitely a progression wrt. the assembly
in the audit trail.

> .L2:
>         rcall f
>         ldi r25,lo8(1)
>         eor r25,r24
>         sbrs r25,0
>         rjmp .L2

I found an avr tutorial at

   http://www.avr-asm-tutorial.net/avr_en/beginner/index.html

and this tells me that sbrs skips the next instruction if Bit 0 in r25
ist set. I.e. this code looks correct to me.

    regards  Christian

Comment 6 Andrew Pinski 2003-08-03 16:19:17 UTC
Since the patch for PR 11662 fixes this bug, I am closing as a dup of bug 11662.

*** This bug has been marked as a duplicate of 11662 ***