This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/7688: CSE not appearing to be applied to conditional expressions
- From: eric-bugs at omnifarious dot org
- To: gcc-gnats at gcc dot gnu dot org
- Date: 22 Aug 2002 20:35:39 -0000
- Subject: optimization/7688: CSE not appearing to be applied to conditional expressions
- Reply-to: eric-bugs at omnifarious dot org
>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: