| Submitter | edmar |
|---|---|
| Date | April 19, 2011, 6:30 p.m. |
| Message ID | <4DADD4DC.4040305@freescale.com> |
| Download | mbox | patch |
| Permalink | /patch/92045/ |
| State | New |
| Headers | show |
Comments
> The test and-1.c has wrong logic. > In the formula: > y & ~(y & -y) > > The part (y & -y) is always a mask with one bit set, which corresponds > to the least significant "1" bit in y. > The final result is that bit, is set to zero (y & ~mask) > > There is no boolean simplification possible, and the compiler always > produces > a nand instruction. The formula is equal to y & (y-1) , maybe the testcase is testing that? Segher
On 04/20/2011 07:52 PM, Segher Boessenkool wrote: >> The test and-1.c has wrong logic. >> In the formula: >> y & ~(y & -y) >> >> The part (y & -y) is always a mask with one bit set, which corresponds >> to the least significant "1" bit in y. >> The final result is that bit, is set to zero (y & ~mask) >> >> There is no boolean simplification possible, and the compiler always >> produces >> a nand instruction. > > The formula is equal to y & (y-1) , maybe the testcase is testing that? > > > Segher > > > Ah, yes A neg/nand/and should be optimized into a sub -1/and. I will check why this is not happening. Thanks Edmar
Patch
Index: gcc-20100630/gcc/testsuite/gcc.target/powerpc/pr39902-2.c =================================================================== --- gcc-20100630/gcc/testsuite/gcc.target/powerpc/pr39902-2.c (revision 161589) +++ gcc-20100630/gcc/testsuite/gcc.target/powerpc/pr39902-2.c (working copy) @@ -1,7 +1,7 @@ /* Check that simplification "x*(-1)" -> "-x" is not performed for decimal float types. */ -/* { dg-do compile { target { powerpc*-*-linux* && powerpc_fprs } } } */ +/* { dg-do compile { target { powerpc*-*-linux* && { powerpc_fprs && dfp } } } } */ /* { dg-options "-std=gnu99 -O -mcpu=power6" } */ /* { dg-final { scan-assembler-not "fneg" } } */ Index: gcc-20100630/gcc/testsuite/gcc.target/powerpc/dfp-dd.c =================================================================== --- gcc-20100630/gcc/testsuite/gcc.target/powerpc/dfp-dd.c (revision 161589) +++ gcc-20100630/gcc/testsuite/gcc.target/powerpc/dfp-dd.c (working copy) @@ -1,6 +1,6 @@ /* Test generation of DFP instructions for POWER6. */ /* Origin: Janis Johnson <janis187@us.ibm.com> */ -/* { dg-do compile { target { powerpc*-*-linux* && powerpc_fprs } } } */ +/* { dg-do compile { target { powerpc*-*-linux* && { powerpc_fprs && dfp } } } } */ /* { dg-options "-std=gnu99 -mcpu=power6" } */ /* { dg-final { scan-assembler "dadd" } } */ Index: gcc-20100630/gcc/testsuite/gcc.target/powerpc/dfp-td.c =================================================================== --- gcc-20100630/gcc/testsuite/gcc.target/powerpc/dfp-td.c (revision 161589) +++ gcc-20100630/gcc/testsuite/gcc.target/powerpc/dfp-td.c (working copy) @@ -1,6 +1,6 @@ /* Test generation of DFP instructions for POWER6. */ /* Origin: Janis Johnson <janis187@us.ibm.com> */ -/* { dg-do compile { target { powerpc*-*-linux* && powerpc_fprs } } } */ +/* { dg-do compile { target { powerpc*-*-linux* && { powerpc_fprs && dfp } } } } */ /* { dg-options "-std=gnu99 -mcpu=power6" } */ /* { dg-final { scan-assembler "daddq" } } */ Index: gcc-20100630/gcc/testsuite/gcc.dg/and-1.c =================================================================== --- gcc-20100630/gcc/testsuite/gcc.dg/and-1.c (revision 161589) +++ gcc-20100630/gcc/testsuite/gcc.dg/and-1.c (working copy) @@ -3,8 +3,9 @@ /* { dg-final { scan-assembler "and" { target powerpc*-*-* spu-*-* } } } */ /* There should be no nand for this testcase (for either PPC or SPU). */ /* { dg-final { scan-assembler-not "nand" { target powerpc*-*-* spu-*-* } } } */ +/* { dg-final { scan-assembler-not "orc" { target powerpc*-*-* spu-*-* } } } */ -int f(int y) +int f(int y, int x) { - return y & ~(y & -y); + return y & ~(y & ~x); }