This is the mail archive of the gcc-bugs@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]

[Bug tree-optimization/31966] [4.1/4.2/4.3 Regression] Miscompiles valid code with -ftree-vectorize



------- Comment #5 from ubizjak at gmail dot com  2007-07-01 09:33 -------
Confirmed. This is the same bug as PR32533, but this one comes with the c
testcase. The problem is in ifcvt pass.

In -march=nocona case (-march=nocona -O2 -ftree-vectorize), we have following
code before ifcvt pass:

  if (high_top_bit_11 != 0)
    goto <bb 5>;
  else
    goto <bb 4>;

<bb 4>:
  if (d_7(D) <= high_19)
    goto <bb 5>;
  else
    goto <bb 6>;

<bb 5>:
  high_21 = high_19 - d_7(D);
  quotient_22 = quotient_20 | 1;

<bb 6>:
  # quotient_3 = PHI <quotient_20(4), quotient_22(5)>
  # high_1 = PHI <high_19(4), high_21(5)>
  j_23 = j_32 + 1;

This code is converted by ifcvt pass to:

  quotient_20 = quotient_31 << 1;          [+]
  D.2068_5 = high_top_bit_11 == 0;
  D.2069_4 = d_7(D) <= high_19;
  _ifc_.29_2 = D.2068_5 && D.2069_4;
  D.2071_29 = high_top_bit_11 == 0;
  D.2072_33 = d_7(D) > high_19;
  _ifc_.30_34 = D.2071_29 && D.2072_33;
  high_21 = high_19 - d_7(D);
  quotient_22 = quotient_20 | 1;           [++]
  quotient_3 = high_top_bit_11 == 0 ? quotient_20 : quotient_22;   <<< here!
  high_1 = high_top_bit_11 == 0 ? high_19 : high_21;               <<< here!
  j_23 = j_32 + 1;

The condition for quotient_3 [and high_1], produced by ifcvt pass is wrong, and
should be:

  quotient_3 = _ifc_.3034 ? quotient_20 : quotient_22;

This is evident from the inner loop of the testcase:

--cut here--
      {
      word high_top_bit = (high & MP_WORD_TOP_BIT);

      high <<= 1;
      high |= (n0 >> (MP_WORD_BITS-1-j)) & 1;
      quotient <<= 1;                                [+]

      if(high_top_bit || high >= d)                  <<<< _the_condition_
         {
         high -= d;
         quotient |= 1;                              [++]
         }
      }
--cut here--

Due to slighlty different gimple generation for -march=core2 (please look into
_.004t.gimple) where only if branch is created, ifcvt is able to create correct
code:

  quotient_20 = quotient_34 << 1;                           [+]
  D.2065_21 = high_top_bit_11 != 0;
  D.2066_22 = high_19 >= d_7(D);
  D.2067_23 = D.2065_21 || D.2066_22;
  high_24 = high_19 - d_7(D);
  quotient_25 = quotient_20 | 1;                            [++]
  quotient_3 = D.2067_23 ? quotient_25 : quotient_20;       <<<<  here


-- 

ubizjak at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ubizjak at gmail dot com
           Priority|P3                          |P1
            Summary|Miscompiles valid code with |[4.1/4.2/4.3 Regression]
                   |-ftree-vectorize and -      |Miscompiles valid code with
                   |march=nocona                |-ftree-vectorize
   Target Milestone|---                         |4.1.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31966


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