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 */
I can confirm this on the mainline (20030706) but with -Os.
This appears to be a duplicate of 11662. Could you try the patch attached to that report and see if that help? regards Christian
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?)?
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.
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
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 ***