avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] [bug] uint16_t optimization error for 8-bit AVRs.


From: Lv Zheng
Subject: Re: [avr-gcc-list] [bug] uint16_t optimization error for 8-bit AVRs.
Date: Wed, 29 Feb 2012 12:19:38 +0800

In the code below, avr-gcc can generate errornous result at Os. It could be a known bug as PR39633.

$ avr-gcc -Os -v -save-temps -dp -o avr-bug.o -c avr-bug.c
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/local/avr/libexec/gcc/avr/4.5.2/lto-wrapper
Target: avr
Configured with: ../../../gcc-4.5.2/configure --target=avr --prefix=/usr/local/avr --with-gmp=/usr/local/avr --with-mpfr=/usr/local/avr --with-mpc=/usr/local/avr --with-dwarf2 --disable-nls --disable-threads --disable-shared --disable-multilib --disable-libada --disable-libssp --disable-libmudflap --enable-target-optspace --enable-languages=c
Thread model: single
gcc version 4.5.2 (GCC)
COLLECT_GCC_OPTIONS='-Os' '-v' '-save-temps' '-dp' '-o' 'avr-bug.o' '-c'
/usr/local/avr/libexec/gcc/avr/4.5.2/cc1 -E -quiet -v avr-bug.c -Os -fpch-preprocess -o avr-bug.i ignoring nonexistent directory "/usr/local/avr/lib/gcc/avr/4.5.2/../../../../avr/sys-include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/avr/lib/gcc/avr/4.5.2/include
/usr/local/avr/lib/gcc/avr/4.5.2/include-fixed
/usr/local/avr/lib/gcc/avr/4.5.2/../../../../avr/include
End of search list.
COLLECT_GCC_OPTIONS='-Os' '-v' '-save-temps' '-dp' '-o' 'avr-bug.o' '-c'
/usr/local/avr/libexec/gcc/avr/4.5.2/cc1 -fpreprocessed avr-bug.i -quiet -dumpbase avr-bug.c -dp -auxbase-strip avr-bug.o -Os -version -o avr-bug.s
GNU C (GCC) version 4.5.2 (avr)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129302
GNU C (GCC) version 4.5.2 (avr)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129302
Compiler executable checksum: 5ab3f29dbbb68c653e4e0a10090c3fc4
COLLECT_GCC_OPTIONS='-Os' '-v' '-save-temps' '-dp' '-o' 'avr-bug.o' '-c'
/usr/local/avr/lib/gcc/avr/4.5.2/../../../../avr/bin/as -o avr-bug.o avr-bug.s
COMPILER_PATH=/usr/local/avr/libexec/gcc/avr/4.5.2/:/usr/local/avr/libexec/gcc/avr/4.5.2/:/usr/local/avr/libexec/gcc/avr/:/usr/local/avr/lib/gcc/avr/4.5.2/:/usr/local/avr/lib/gcc/avr/:/usr/local/avr/lib/gcc/avr/4.5.2/../../../../avr/bin/
LIBRARY_PATH=/usr/local/avr/lib/gcc/avr/4.5.2/:/usr/local/avr/lib/gcc/avr/4.5.2/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-Os' '-v' '-save-temps' '-dp' '-o' 'avr-bug.o' '-c'

$ cat avr-bug.c
#define MAKEWORD(a, b)   ((a) | ((unsigned short)(b) << 8))

unsigned char force_z_ref[200];

static unsigned char casted_range_check_opt(unsigned short reg)
{
return (reg >= 100) && (reg < 200);
}

extern unsigned char avoid_further_opt(void);

void bug_playback(void)
{
unsigned char i;
unsigned short reg;
unsigned char val;

for (i = 0; i < (force_z_ref[3]-2); i += 2) {
 reg = MAKEWORD(force_z_ref[8+i],
         force_z_ref[7+i]);
 if (!casted_range_check_opt(reg)) {
  val = avoid_further_opt();
 }
}
}

$ cat avr-bug.s
.file "avr-bug.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
.text
.global bug_playback
.type bug_playback, @function
bug_playback:
push r14  ;  67 *pushqi/1 [length = 1]
push r15  ;  68 *pushqi/1 [length = 1]
push r17  ;  69 *pushqi/1 [length = 1]
push r28  ;  70 *pushqi/1 [length = 1]
push r29  ;  71 *pushqi/1 [length = 1]
/* prologue: function */
/* frame size = 0 */
/* stack size = 5 */
.L__stack_usage = 5
ldi r17,lo8(0)  ;  6 *movqi/1 [length = 1]
rjmp .L2  ;  82 jump [length = 1]
.L4:
mov r30,r18  ;  56 *movhi/1 [length = 2]
mov r31,r19
subi r30,lo8(-(force_z_ref))  ;  13 *addhi3/4 [length = 2]
sbci r31,hi8(-(force_z_ref))
ldi r24,lo8(0)  ;  50 *movqi/1 [length = 1]
mov r28,r24  ;  60 *movhi/1 [length = 2]
mov r29,r25
ldd r24,Z+8  ;  21 *movqi/4 [length = 1]
ldi r25,lo8(0)  ;  66 *movqi/1 [length = 1]
or r24,r28  ;  23 iorhi3/1 [length = 2]
or r25,r29
subi r24,lo8(-(-100))  ;  24 *addhi3/4 [length = 2]
sbci r25,hi8(-(-100))
cpi r24,100  ;  25 *cmphi/4 [length = 2]
cpc r25,__zero_reg__
brlo .L3  ;  26 branch [length = 1]
rcall avoid_further_opt  ;  29 call_value_insn/3 [length = 1]
.L3:
subi r17,lo8(-(2))  ;  32 addqi3/2 [length = 1]
.L2:
mov r18,r17  ;  61 *movqi/1 [length = 1]
ldi r19,lo8(0)  ;  62 *movqi/1 [length = 1]
lds r24,force_z_ref+3  ;  38 *movqi/4 [length = 2]
ldi r25,lo8(0)  ;  64 *movqi/1 [length = 1]
sbiw r24,2  ;  40 *addhi3/3 [length = 1]
cp r18,r24  ;  41 *cmphi/3 [length = 2]
cpc r19,r25
brlt .L4  ;  42 branch [length = 1]
/* epilogue start */
pop r29  ;  74 popqi [length = 1]
pop r28  ;  75 popqi [length = 1]
pop r17  ;  76 popqi [length = 1]
pop r15  ;  77 popqi [length = 1]
pop r14  ;  78 popqi [length = 1]
ret  ;  79 return_from_epilogue [length = 1]
.size bug_playback, .-bug_playback
.comm force_z_ref,200,1

Best regards/Lv ZETALOG Zheng




reply via email to

[Prev in Thread] Current Thread [Next in Thread]