[PATCH] PR/35281 2/2, teach fwprop how to safely handle some MEMs

Paolo Bonzini bonzini@gnu.org
Mon Mar 10 15:18:00 GMT 2008


fwprop does not do alias analysis, and is actually fairly conservative 
about handling read-only MEMs.  Hence it fails to optimize in PR35281 
this RTL:

(insn 9 8 10 2 (parallel [
             (set (reg:DI 60 [ b ])
                 (zero_extend:DI (mem/c/i:SI (symbol_ref:SI ("b") <var_decl
0xb7caf108 b>) [3 b+0 S4 A32])))
             (clobber (reg:CC 17 flags))
         ]) 79 {zero_extendsidi2_32} (nil)
     (nil))

...

(insn 11 10 12 2 (parallel [
             (set (reg:SI 61)
                 (mult:SI (reg:SI 62 [ a ])
                     (subreg:SI (reg:DI 60 [ b ]) 4)))
             (clobber (reg:CC 17 flags))
         ]) 182 {*mulsi3_1} (nil)
     (nil))

which is simply zero.  This patch teaches it to turn MEMs into either a 
combiney (clobber (const_int 0)) or, for non-volatile MEMs, a (scratch).

Using SCRATCH is actually better than a CLOBBER because it shows the 
lack of side-effects; the same optimization would not be possible with a 
volatile mem, but is safe with a normal one.  Combine could be taught 
about it too.

Bootstrapped/regtested i686-pc-linux-gnu, ok for mainline?

Paolo


/* { dg-options "-O2" } */
/* { dg-do compile } */
/* { dg-require-effective-target ilp32 } */

unsigned long long a;
unsigned int b;
unsigned short c;

unsigned long long mul32()
{
   return a * b;
}

unsigned long long mul16()
{
   return a * c;
}

/* { dg-final { scan-assembler-not "xor" } } */
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pr35281.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080310/c7966a76/attachment.ksh>


More information about the Gcc-patches mailing list