This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Global constant propagation


On Sat, Apr 03, 1999 at 01:17:16PM -0700, Jeffrey A Law wrote:
> 
> The code in gcse.c does global constant propagation.  If you have cases
> where it is not working we would like to see examples.

Here is a small C fn:

int testfn(int a, int b)
{
   a = 1;
   if(b == 1)
   {
     b = 2;
   }
   else
   {
     b = 3;
   }
   return a*b;
}

The if-then-else confuses the cprop so it doesn't see that we are
multiplying by 1.  We get (omitting fn entry and exit parts)

        li      $2,1                    # 0x1
        .set    noreorder
        .set    nomacro
        bne     $5,$2,.L3
        li      $3,3                    # 0x3
        .set    macro
        .set    reorder

        li      $3,2                    # 0x2
.L3:
        mult    $2,$3
        mflo    $2

If you get rid of the if-then-else, then egcs sees the multiplication
is by the constant 1, and no multiplication takes place:

int testfn(int a, int b)
{
   a = 1;
   return a*b;
}

gives just

        move    $2,$5

I have egcs-2.93.12 from the 1999-03-14 snapshot configured for
mips-sgi-irix6.5.

-- 
Erik Corry erik@arbat.com     Ceterum censeo, Microsoftem esse delendam!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]