public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "dhowells at redhat dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/58073] New: Suboptimal optimisation of ((x & 0x70) == 0x00 && (x & 0x70) == 0x10 && (x & 0x70) == 0x20) on x86_64 Date: Sat, 03 Aug 2013 17:01:00 -0000 [thread overview] Message-ID: <bug-58073-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58073 Bug ID: 58073 Summary: Suboptimal optimisation of ((x & 0x70) == 0x00 && (x & 0x70) == 0x10 && (x & 0x70) == 0x20) on x86_64 Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dhowells at redhat dot com Created attachment 30605 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30605&action=edit Demonstration source code When the attached demo code is compiled with gcc-4.8.1, two of the cases optimise fine and the third case is optimised suboptimally - probably because it initially matches the optimisation for the second case. Going through the cases individually for 'shift' being 4: (1) return (mask(d) == (0x0 << shift)); This is rendered as a single TEST instruction in x86_64 asm: 0: f6 07 70 testb $0x70,(%rdi) 3: 0f 94 c0 sete %al 6: c3 retq which is good. (2) return (mask(d) == (0x0 << shift) || mask(d) == (0x1 << shift)); This is also rendered as a single TEST instruction: 10: f6 07 60 testb $0x60,(%rdi) 13: 0f 94 c0 sete %al 16: c3 retq which is again good. The problem comes with the third case: (3) return (mask(d) == (0x0 << shift) || mask(d) == (0x1 << shift) || mask(d) == (0x2 << shift)); This is rendered as: 20: 8b 17 mov (%rdi),%edx 22: b8 01 00 00 00 mov $0x1,%eax 27: f6 c2 60 test $0x60,%dl 2a: 74 09 je 35 <foo3+0x15> 2c: 83 e2 70 and $0x70,%edx 2f: 83 fa 20 cmp $0x20,%edx 32: 0f 94 c0 sete %al 35: f3 c3 repz retq which is odd. I would expect the thing to be turned into MOV, AND, CMP, SETE, RETQ since the numbers it is checking for lie adjacent to each other, starting from zero. I think what has happened is that the first two comparisons matched the optimisation for case (2) - resulting in three extra instructions. The compilation command line was: gcc -O2 -c foo.c -Wall && objdump -d foo.o The compiler version: Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.1/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-isl=/builddir/build/BUILD/gcc-4.8.1-20130603/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.1-20130603/obj-x86_64-redhat-linux/cloog-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 4.8.1 20130603 (Red Hat 4.8.1-1) (GCC) as supplied by Fedora: gcc-4.8.1-1.fc19.x86_64
next reply other threads:[~2013-08-03 17:01 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-08-03 17:01 dhowells at redhat dot com [this message] 2013-08-03 17:06 ` [Bug c/58073] " dhowells at redhat dot com 2021-06-04 22:18 ` [Bug tree-optimization/58073] Suboptimal optimisation of ((x & 0x70) == 0x00 || (x & 0x70) == 0x10 || " pinskia at gcc dot gnu.org 2021-06-04 22:32 ` [Bug tree-optimization/58073] Suboptimal optimisation of ((x & 0x70) == 0x00 || (x & 0x70) == 0x10 || (x & 0x70) == 0x20) pinskia at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-58073-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).