This is GCC Bugzilla
This is GCC Bugzilla Version 2.20+
View Bug Activity | Format For Printing | Clone This Bug
Using this version/config: ~~~~~~~~~~~~~~~~~ Using built-in specs. Target: avr Configured with: ../gcc-4.1.2/configure --prefix=/c/WinAVR --target=avr --enable -languages=c,c++ --with-dwarf2 --enable-win32-registry=WinAVR-20070525 --disable -nls --with-gmp=/usr/local --with-mpfr=/usr/local --enable-doc --disable-libssp Thread model: single gcc version 4.1.2 (WinAVR 20070525) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ I compiled the source using this command line: avr-gcc -S -Os test.c -mmcu=atmega16 These examples also suffers from double and instruction missed (bugID 11259) The key point is that writing an expression like: tmp = 0; if(var&(1<<N)) tmp|=1; results in an N shift (done by loop if N larger then 3) While rewriting to: tmp = 0; if(var>>N)&1) tmp|=1; This uses a swap instruction and then shifts. It's optimal (except from the same loss as bugID 12259 for N >= 4) Maybe this gives a hint on where the shifting is generally going wrong. I tried 3 approaches in the test.c file. Another interresting thing is the removal off the extra and instructions in the last examples in the file.
Created an attachment (id=14053) [edit] examples of good extraction and bad extraction Adding the test file showing the missed optimization
It might be interesting if you tried 4.2.1.
Wouter, please attach the assembly output that you are getting for your test.c file using 4.1.2. That way we can compare it to other compiler versions. Thanks, Eric
Created an attachment (id=14105) [edit] Assembler output of testcase using 4.1.2 This is the requested assembler output that Eric asked for
Created an attachment (id=14106) [edit] Correct assembler output of test case for 4.1.2.
Created an attachment (id=14107) [edit] Test case assembler output for 4.2.1. Not really any better than 4.1.2.
Created an attachment (id=14108) [edit] Test case assembler output for 4.3.0 20070817 snapshot. Again, only marginally better.