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]
Other format: [Raw text]

RE: A case exposing code sink issue


Sorry, I realize we can't do that optimization because a_p may have
dependence upon other memory accesses like MEM[(int *)&a][D.2248_7].

For example, if it happens a_p equals &a_p, that optimization would be
wrong.

But can alias analysis solve the problem if we can guarantee (i+(1<<k)) is
less than the upbound of array a's definition? 

Or is there any GCC command line switch assuming no array bound overflow?
That way we can do more aggressive optimizations, right?

Thanks,
-Jiangning

> -----Original Message-----
> From: gcc-owner@gcc.gnu.org [mailto:gcc-owner@gcc.gnu.org] On Behalf Of
> Jiangning Liu
> Sent: Thursday, November 24, 2011 12:05 PM
> To: gcc@gcc.gnu.org
> Subject: A case exposing code sink issue
> 
> Hi,
> 
> For this small test case,
> 
> int a[512] ;
> int b[512] ;
> int *a_p ;
> int *b_p ;
> int i ;
> int k ;
> 
> int f(void)
> {
>         for( k = 1 ; k <= 9 ; k++)
>         {
>                 for( i = k ; i < 512 ; i += k)
>                 {
>                         a_p = &a[i + (1<<k)] ;
>                         b_p = &b[i + (1<<k)] ;
>                         *a_p = 7 ;
>                         *b_p = 7 ;
>                 }
>         }
> }
> 
> Before sink pass we have,
> 
> f ()
> {
>   int pretmp.11;
>   int k.7;
>   int i.6;
>   int * b_p.3;
>   int * a_p.2;
>   int D.2248;
>   int i.1;
>   int D.2246;
>   int k.0;
> 
> <bb 2>:
>   k = 1;
> 
> <bb 3>:
>   # k.0_9 = PHI <k.7_20(11), 1(2)>
>   i = k.0_9;
>   if (k.0_9 <= 511)
>     goto <bb 7>;
>   else
>     goto <bb 8>;
> 
> <bb 8>:
> Invalid sum of incoming frequencies 900, should be 81
>   goto <bb 5>;
> 
> <bb 7>:
>   pretmp.11_19 = 1 << k.0_9;
> 
> <bb 4>:
>   # i.1_34 = PHI <i.6_18(9), k.0_9(7)>
>   D.2246_5 = pretmp.11_19;
>   D.2248_7 = i.1_34 + D.2246_5;
>   a_p.2_8 = &a[D.2248_7];
>   a_p = a_p.2_8;
>   b_p.3_13 = &b[D.2248_7];
>   b_p = b_p.3_13;
>   MEM[(int *)&a][D.2248_7] = 7;
>   MEM[(int *)&b][D.2248_7] = 7;
>   i.6_18 = k.0_9 + i.1_34;
>   i = i.6_18;
>   if (i.6_18 <= 511)
>     goto <bb 9>;
>   else
>     goto <bb 8>;
> 
> <bb 9>:
>   goto <bb 4>;
> 
> <bb 5>:
> Invalid sum of incoming frequencies 81, should be 900
>   k.7_20 = k.0_9 + 1;
>   k = k.7_20;
>   if (k.7_20 <= 9)
>     goto <bb 11>;
>   else
>     goto <bb 6>;
> 
> <bb 11>:
>   goto <bb 3>;
> 
> <bb 6>:
>   return;
> 
> }
> 
> Can the following statements be sinked out of loop? I don't see this
> optimization happen in trunk. The consequence is register pressure
> increased
> and a spill/fill occurs in RA.
> 
>   a_p.2_8 = &a[D.2248_7];
>   a_p = a_p.2_8;
>   b_p.3_13 = &b[D.2248_7];
>   b_p = b_p.3_13;
> 
> I know the sink would happen in sink pass if a_p and b_p are local
> variables.
> 
> If this is the root cause, which optimization pass in GCC take the role
> to
> sink them out of loop? How should we get it fixed?
> 
> Thanks,
> -Jiangning
> 
> 
> 





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