public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: eric-bugs@omnifarious.org
To: gcc-gnats@gcc.gnu.org
Subject: optimization/7688: CSE not appearing to be applied to conditional expressions
Date: Thu, 22 Aug 2002 13:46:00 -0000	[thread overview]
Message-ID: <20020822203539.27926.qmail@sources.redhat.com> (raw)


>Number:         7688
>Category:       optimization
>Synopsis:       CSE not appearing to be applied to conditional expressions
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 22 13:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Eric Hopper
>Release:        gcc-3.2
>Organization:
>Environment:
RedHat Linux 7.3 with a hand-compiled and installed gcc.
>Description:
This code:

--------------
extern void fred(unsigned int digit);

void test(const unsigned int * const buf32, const unsigned int len)
{
   for (int i = 0; i < len; ++i) {
      const unsigned int ch32 = buf32[i];
      if ((ch32 >= '0' && (ch32 <= '9')) ||
          ((ch32 >= 'A') && (ch32 <= 'F')) ||
          ((ch32 >= 'a') && (ch32 <= 'f')))
      {
         unsigned int digit = 0;
         if ((ch32 >= '0') && (ch32 <= '9'))
         {
            digit = ch32 - '0';
         }
         else if ((ch32 >= 'A') && (ch32 <= 'F'))
         {
            digit = (ch32 - 'A') + 10;
         }
         else if ((ch32 >= 'a') && (ch32 <= 'f'))
         {
            digit = (ch32 - 'a') + 10;
         }
         fred(digit);
      }
   }
}

void test2(const unsigned int * const buf32, const unsigned int len)
{
   for (int i = 0; i < len; ++i) {
      const unsigned int ch32 = buf32[i];
      if (ch32 >= '0' && (ch32 <= '9'))
      {
         fred(ch32 - '0');
      } else if ((ch32 >= 'A') && (ch32 <= 'F')) {
         fred((ch32 - 'A') + 10);
      } else if ((ch32 >= 'a') && (ch32 <= 'f')) {
         fred((ch32 - 'a') + 10);
      }
   }
}
-------------------

when compiled with this command line:

/usr/local/gcc-3.2/bin/g++ -v -pipe -march=athlon-xp -O3 -S testswitch.cxx

generates this output:

Reading specs from /usr/local/gcc-3.2/lib/gcc-lib/athlon-pc-linux-gnu/3.2/specs
Configured with: ../gcc-3.2/configure --prefix=/usr/local/gcc-3.2 --with-cpu=athlon athlon-pc-linux-gnu --enable-languages=c,c++
Thread model: posix
gcc version 3.2
 /usr/local/gcc-3.2/lib/gcc-lib/athlon-pc-linux-gnu/3.2/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=2 -D__GNUC_PATCHLEVEL__=0 -D__GXX_ABI_VERSION=102 -D__ELF__ -Dunix -D__gnu_linux__ -Dlinux -D__ELF__ -D__unix__ -D__gnu_linux__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__athlon -D__athlon__ -D__athlon_sse__ -D__tune_athlon__ -D__tune_athlon_sse__ -D__SSE__ -D__MMX__ -D__3dNOW__ -D__3dNOW_A__ testswitch.cxx -D__GNUG__=3 -D__DEPRECATED -D__EXCEPTIONS -quiet -dumpbase testswitch.cxx -march=athlon-xp -O3 -version -o testswitch.s
GNU CPP version 3.2 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.2 (athlon-pc-linux-gnu)
        compiled by GNU C version 3.2.
ignoring nonexistent directory "/usr/local/gcc-3.2/athlon-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc-3.2/include/c++/3.2
 /usr/local/gcc-3.2/include/c++/3.2/athlon-pc-linux-gnu
 /usr/local/gcc-3.2/include/c++/3.2/backward
 /usr/local/include
 /usr/local/gcc-3.2/include
 /usr/local/gcc-3.2/lib/gcc-lib/athlon-pc-linux-gnu/3.2/include
 /usr/include
End of search list.

and the assembly file, testswitch.s, has code for the test1 and test2 functions that's fairly different.  In particular, the assembly for the test1 function runs the tests twice, even though the tests are exactly the same, and there is no possible way the value being tested could've changed between the tests.

Now it's arguable that test2 is both more concise and clearer, but I suspect there are instances in which that isn't the case.
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


                 reply	other threads:[~2002-08-22 20:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20020822203539.27926.qmail@sources.redhat.com \
    --to=eric-bugs@omnifarious.org \
    --cc=gcc-gnats@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: link
Be 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).