Hi,

I'm trying to improve the asm code generated for C code like:

  long f(long a, long b) {
    _int64 s;

    s = (((long long) a) + ((long long) b));

    s = (s > 0x7fffffffL ? (long) 0x7fffffffL : 
        (s <-0x80000000L ? (long)-0x80000000L : 
                            s));

    return((long) s);
  }

A key step is minmax detection in tree-ssa-phiopt.c.  However, in my test cases 
sometimes minmax detection fails because of input like:

  if (D.5591_11 <= 2147483647)
      goto <bb 3>;
    else
      goto <bb 4>;

  <bb 3>:
    D.5594_19 = MAX_EXPR <D.5591_11, -2147483648>;
    iftmp.0_20 = (long int) D.5594_19;

  <bb 4>:
    # iftmp.0_1 = PHI <iftmp.0_20(3), 2147483647(2)>


Minmax detection expects the middle block to have one statement, but in this 
case there is an additional cast.  Minmax would be detected if the cast
was moved after the middle block:

  ...
  <bb 3>:
    D.5594_19 = MAX_EXPR <D.5591_11, -2147483648>;

  <bb 4>:
    # s_1 = PHI <D.5594_19, 2147483647(2)>
    iftmp.0_20 = (long int) s_1;

The limitation occurs around line 725 in tree-ssa-phiopt.c in GCC 4.5.2:

      /* Recognize the following case, assuming d <= u:

         if (a <= u)
           b = MAX (a, d);
         x = PHI <b, u>

         This is equivalent to

         b = MAX (a, d);
         x = MIN (b, u);  */

      gimple assign = last_and_only_stmt (middle_bb);
      tree lhs, op0, op1, bound;

I was wondering if anyone could give me guidance on how to add flexibility
to minmax detection in order to handle this case.

Thanks,
John Lu



Reply via email to