public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations @ 2013-07-24 11:08 daniel.blaukopf at oracle dot com 2013-07-24 11:09 ` [Bug rtl-optimization/57967] " daniel.blaukopf at oracle dot com ` (5 more replies) 0 siblings, 6 replies; 7+ messages in thread From: daniel.blaukopf at oracle dot com @ 2013-07-24 11:08 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 Bug ID: 57967 Summary: Incorrect code generated on ARM with -fexpensive-optimizations Product: gcc Version: 4.6.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: daniel.blaukopf at oracle dot com Created attachment 30543 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30543&action=edit Two functions, f1 and f2 should compile to almost the same result. The compiled code for f1 throws away the x0 and x1 parameters. In situations results of a computation that go into the top 16-bits of a 32-bit return value are optimized out. A small change to the source makes the problem go away. In the example provided, changing the order of function parameters provides the problem. - Reproduced on the ARM GCC 4.6.3 in Ubuntu 12.04 (both hard and soft float) by inspection of generated assembly - Reproduced on the Linaro GCC 4.7.2 unsupported 2012.09 toolchain from https://launchpad.net/linaro-toolchain-unsupported/, verified by inspection of generated assembly and by running a test case. + arm-linux-gnueabihf-gcc -v --save-temps -Wall -Wextra -shared -O -fexpensive-optimizations gcc-bug.c -o libgcc-bug.so Using built-in specs. COLLECT_GCC=arm-linux-gnueabihf-gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper Target: arm-linux-gnueabihf Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/arm-linux-gnueabihf/include/c++/4.6.3 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-float=hard --with-fpu=vfpv3-d16 --with-mode=thumb --disable-werror --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include --with-headers=/usr/arm-linux-gnueabihf/include --with-libs=/usr/arm-linux-gnueabihf/lib Thread model: posix gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared' '-O' '-fexpensive-optimizations' '-o' 'libgcc-bug.so' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' /usr/lib/gcc/arm-linux-gnueabihf/4.6/cc1 -E -quiet -v -imultilib . -imultiarch arm-linux-gnueabihf gcc-bug.c -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -mthumb -Wall -Wextra -fexpensive-optimizations -O -fpch-preprocess -fstack-protector -o gcc-bug.i ignoring duplicate directory "/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/include" ignoring nonexistent directory "/usr/include/arm-linux-gnueabihf" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/arm-linux-gnueabihf/4.6/include /usr/lib/gcc/arm-linux-gnueabihf/4.6/include-fixed /usr/arm-linux-gnueabihf/include /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared' '-O' '-fexpensive-optimizations' '-o' 'libgcc-bug.so' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' /usr/lib/gcc/arm-linux-gnueabihf/4.6/cc1 -fpreprocessed gcc-bug.i -quiet -dumpbase gcc-bug.c -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -mthumb -auxbase gcc-bug -O -Wall -Wextra -version -fexpensive-optimizations -fstack-protector -o gcc-bug.s GNU C (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (arm-linux-gnueabihf) compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (arm-linux-gnueabihf) compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: cc9c163e1be35f3de7fa1357bc204e65 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared' '-O' '-fexpensive-optimizations' '-o' 'libgcc-bug.so' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/bin/as -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -meabi=5 -o gcc-bug.o gcc-bug.s COMPILER_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/bin/ LIBRARY_PATH=/usr/lib/gcc/arm-linux-gnueabihf/4.6/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib/../lib/:/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-Wextra' '-shared' '-O' '-fexpensive-optimizations' '-o' 'libgcc-bug.so' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' /usr/lib/gcc/arm-linux-gnueabihf/4.6/collect2 --build-id --no-add-needed --as-needed --eh-frame-hdr -shared -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=gnu -m armelf_linux_eabi -z relro -o libgcc-bug.so /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib/../lib/crti.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/crtbeginS.o -L/usr/lib/gcc/arm-linux-gnueabihf/4.6 -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib/../lib -L/usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib -L/lib/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf -L/usr/lib -L/lib gcc-bug.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/arm-linux-gnueabihf/4.6/crtendS.o /usr/lib/gcc/arm-linux-gnueabihf/4.6/../../../../arm-linux-gnueabihf/lib/../lib/crtn.o ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/57967] Incorrect code generated on ARM with -fexpensive-optimizations 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com @ 2013-07-24 11:09 ` daniel.blaukopf at oracle dot com 2013-07-24 11:16 ` daniel.blaukopf at oracle dot com ` (4 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: daniel.blaukopf at oracle dot com @ 2013-07-24 11:09 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 --- Comment #1 from Daniel Blaukopf <daniel.blaukopf at oracle dot com> --- Created attachment 30544 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30544&action=edit Test case that can be run with libgcc-bug.so to show the failure ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/57967] Incorrect code generated on ARM with -fexpensive-optimizations 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com 2013-07-24 11:09 ` [Bug rtl-optimization/57967] " daniel.blaukopf at oracle dot com @ 2013-07-24 11:16 ` daniel.blaukopf at oracle dot com 2013-07-24 15:45 ` [Bug rtl-optimization/57967] [4.7 regresssion] " rearnsha at gcc dot gnu.org ` (3 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: daniel.blaukopf at oracle dot com @ 2013-07-24 11:16 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 --- Comment #2 from Daniel Blaukopf <daniel.blaukopf at oracle dot com> --- This code: int f1(int x0, int y0, int z0, int x1, int y1, int z1) { int xx = ((x0 << 16) + (x1 - x0) * 0x1234 + 0x8000) >> 16; int yy = ((y0 << 16) + (y1 - y0) * 0x2345 + 0x8000) >> 16; int zz = ((z0 << 16) + (z1 - z0) * 0x3456 + 0x8000) >> 16; return (xx << 16) | (yy << 8) | zz; } Compiles (incorrectly) to: f1: @ args = 8, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. ldr r0, [sp, #4] subs r0, r0, r2 movw r3, #13398 mul r0, r3, r0 add r2, r0, r2, lsl #16 ldr r3, [sp, #0] subs r3, r3, r1 movw r0, #9029 mul r3, r0, r3 add r1, r3, r1, lsl #16 add r1, r1, #32768 asr r1, r1, #16 lsl r1, r1, #8 add r0, r2, #32768 orr r0, r1, r0, asr #16 bx lr This almost identical code: int f2(int x0, int x1, int y0, int y1, int z0, int z1) { int xx = ((x0 << 16) + (x1 - x0) * 0x1234 + 0x8000) >> 16; int yy = ((y0 << 16) + (y1 - y0) * 0x2345 + 0x8000) >> 16; int zz = ((z0 << 16) + (z1 - z0) * 0x3456 + 0x8000) >> 16; return (xx << 16) | (yy << 8) | zz; } Compiles (correctly) to: f2: @ args = 8, pretend = 0, frame = 0 @ frame_needed = 0, uses_anonymous_args = 0 @ link register save eliminated. push {r4, r5} ldr r4, [sp, #8] subs r3, r3, r2 movw r5, #9029 mul r3, r5, r3 add r2, r3, r2, lsl #16 add r2, r2, #32768 asr r2, r2, #16 subs r1, r1, r0 movw r3, #4660 mul r1, r3, r1 add r0, r1, r0, lsl #16 add r0, r0, #32768 asr r0, r0, #16 lsl r0, r0, #16 orr r2, r0, r2, lsl #8 ldr r0, [sp, #12] subs r0, r0, r4 movw r3, #13398 mul r0, r3, r0 add r4, r0, r4, lsl #16 add r0, r4, #32768 orr r0, r2, r0, asr #16 pop {r4, r5} bx lr ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/57967] [4.7 regresssion] Incorrect code generated on ARM with -fexpensive-optimizations 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com 2013-07-24 11:09 ` [Bug rtl-optimization/57967] " daniel.blaukopf at oracle dot com 2013-07-24 11:16 ` daniel.blaukopf at oracle dot com @ 2013-07-24 15:45 ` rearnsha at gcc dot gnu.org 2013-07-25 13:59 ` mikpe at it dot uu.se ` (2 subsequent siblings) 5 siblings, 0 replies; 7+ messages in thread From: rearnsha at gcc dot gnu.org @ 2013-07-24 15:45 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 Richard Earnshaw <rearnsha at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2013-07-24 Known to work| |4.8.2 Summary|Incorrect code generated on |[4.7 regresssion] Incorrect |ARM with |code generated on ARM with |-fexpensive-optimizations |-fexpensive-optimizations Ever confirmed|0 |1 --- Comment #3 from Richard Earnshaw <rearnsha at gcc dot gnu.org> --- This appears to be a bug in combine. My suspicion lies with the new 4-way combine code that was added around gcc-4.6. Note that gcc-4.6 is no-longer being maintained. The problem seems to be fixed in 4.8 so a bisect might indicate a fix. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/57967] [4.7 regresssion] Incorrect code generated on ARM with -fexpensive-optimizations 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com ` (2 preceding siblings ...) 2013-07-24 15:45 ` [Bug rtl-optimization/57967] [4.7 regresssion] " rearnsha at gcc dot gnu.org @ 2013-07-25 13:59 ` mikpe at it dot uu.se 2013-08-28 9:22 ` rguenth at gcc dot gnu.org 2014-06-12 13:52 ` rguenth at gcc dot gnu.org 5 siblings, 0 replies; 7+ messages in thread From: mikpe at it dot uu.se @ 2013-07-25 13:59 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 --- Comment #4 from Mikael Pettersson <mikpe at it dot uu.se> --- I can reproduce the wrong-code with gcc-4.7.3 on armv5tel-linux-gnueabi. The wrong-code disappeared on 4.7 branch with the recent PR57829 fix in r200773. On trunk the wrong-code disappeared with r186147, Mike Stump's "remove wrong code in immed_double_const" patch. Backporting that to 4.7.3 (pre-PR57829 fix) also fixes the wrong-code. However, r186147 (a) had some regressions on ARM and s390x (see PR57735), and (b) should be redundant for 4.7 given the PR57829 fix. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/57967] [4.7 regresssion] Incorrect code generated on ARM with -fexpensive-optimizations 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com ` (3 preceding siblings ...) 2013-07-25 13:59 ` mikpe at it dot uu.se @ 2013-08-28 9:22 ` rguenth at gcc dot gnu.org 2014-06-12 13:52 ` rguenth at gcc dot gnu.org 5 siblings, 0 replies; 7+ messages in thread From: rguenth at gcc dot gnu.org @ 2013-08-28 9:22 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |4.7.4 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug rtl-optimization/57967] [4.7 regresssion] Incorrect code generated on ARM with -fexpensive-optimizations 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com ` (4 preceding siblings ...) 2013-08-28 9:22 ` rguenth at gcc dot gnu.org @ 2014-06-12 13:52 ` rguenth at gcc dot gnu.org 5 siblings, 0 replies; 7+ messages in thread From: rguenth at gcc dot gnu.org @ 2014-06-12 13:52 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57967 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED Target Milestone|4.7.4 |4.8.2 --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- Fixed in 4.8.2. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-06-12 13:52 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2013-07-24 11:08 [Bug rtl-optimization/57967] New: Incorrect code generated on ARM with -fexpensive-optimizations daniel.blaukopf at oracle dot com 2013-07-24 11:09 ` [Bug rtl-optimization/57967] " daniel.blaukopf at oracle dot com 2013-07-24 11:16 ` daniel.blaukopf at oracle dot com 2013-07-24 15:45 ` [Bug rtl-optimization/57967] [4.7 regresssion] " rearnsha at gcc dot gnu.org 2013-07-25 13:59 ` mikpe at it dot uu.se 2013-08-28 9:22 ` rguenth at gcc dot gnu.org 2014-06-12 13:52 ` rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).