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: predicated code motion (in lim)


On Fri, Oct 10, 2014 at 3:44 PM, Evgeniya Maenkova
<evgeniya.maenkova@gmail.com> wrote:
> Hi,
> could anyone clarify about predicated code motion in lim?
>
> After reading a TODO in /tree-ssa-loop-im.c (see [1]) I tried several
> examples, say [2]. However, in all of them the code was moved out of
> the loop successfully (either by pre or by lim, as in [2]).
>
> So my question is: what the author of this code did mean by
> "predicated code motion"? (what is the TODO)

It means transforming

> Thanks,
>
> Evgeniya
>
> [1]
> TODO:  Support for predicated code motion.  I.e.
>
>    while (1)
>      {
>        if (cond)
>          {
>            a = inv;
>            something;
>          }
>      }

this to

    if (cond)
     {
       a= inv;
       something;
     }
   while (1)
     ;

which is currently supported in a very limited way by emitting
this as

   a = cond ? inv : a;

for at most two statements.  As it executes stmts unconditionally
that way it is limited to non-trapping operations.

Richard.


> [2]
>
> void foo(int cond, int inv)
> {
>
>     int a;
>     int i = 0;
>     int j = 0;
>     while (j++ < 100) {
>         while (i++ < 2000)
>          {
>            if (j % 2)
>             {
>                 a = 528*j;
>                 printf("Hey1%d %d", a, i);//something;
>              }
>         }
>
>      }
> }
>
> lim:
>
> ;; Function foo (foo, funcdef_no=0, decl_uid=1394, cgraph_uid=0, symbol_order=0)
>
> foo (int cond, int inv)
> {
>   int j;
>   int i;
>   int a;
>   unsigned int j.0_12;
>   unsigned int _13;
>   unsigned int _18;
>   unsigned int _21;
>
>   <bb 2>:
>   goto <bb 8>;
>
>   <bb 3>:
>   if (_13 != 0)
>     goto <bb 4>;
>   else
>     goto <bb 10>;
>
>   <bb 10>:
>   goto <bb 5>;
>
>   <bb 4>:
>   printf ("Hey1%d %d", a_14, i_11);
>
>   <bb 5>:
>
>   <bb 6>:
>   # i_1 = PHI <i_22(8), i_11(5)>
>   i_11 = i_1 + 1;
>   if (i_1 <= 1999)
>     goto <bb 3>;
>   else
>     goto <bb 7>;
>
>   <bb 7>:
>   # i_20 = PHI <i_11(6)>
>   j_9 = j_23 + 1;
>   if (j_23 != 100)
>     goto <bb 11>;
>   else
>     goto <bb 9>;
>
>   <bb 11>:
>
>   <bb 8>:
>   # i_22 = PHI <i_20(11), 0(2)>
>   # j_23 = PHI <j_9(11), 1(2)>
>   j.0_12 = (unsigned int) j_23;
>   _13 = j.0_12 & 1;
>   _21 = (unsigned int) j_23;
>   _18 = _21 * 528;
>   a_14 = (int) _18;
>   goto <bb 6>;
>
>   <bb 9>:
>   return;
>
> }
>
>
> However, in loopinit (the optimization before lim) there was no motion
> (So this was done by lim:
>   <bb 4>:
>   a_14 = j_23 * 528;
>   printf ("Hey1%d %d", a_14, i_11);


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