https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111764

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Shorter testcase, fails at -O2 -ftree-vectorize

short b;
int main()
{
  b = 2;
  for (int a = 1; a <= 9; a++)
    b = b * b;
  if (b != 0)
    __builtin_abort ();
}

it "works" with unsigned short b because the non-path reduction detection
doesn't allow two uses of 'b':

t.c:5:21: note:   Analyze phi: b_lsm.6_2 = PHI <powmult_3(7), 2(2)>
t.c:5:21: missed:   reduction used in loop.
t.c:5:21: missed:   Unknown def-use cycle pattern.

but the path based reduction detection has

            /* We want to allow x + x but not x < 1 ? x : 2.  */
            if (is_gimple_assign (op_use_stmt)
                && gimple_assign_rhs_code (op_use_stmt) == COND_EXPR)

which also allows x * x to slip through.  Even when fixing the earlier
issue of the initial value we end up with

  vect_b.13_27 = { 2, 1, 1, 1, 1, 1, 1, 1 };
  vect_powmult_5.14_28 = vect_b.13_27 * vect_b.13_27;

allowing x + x is only OK because it's 2 * x and we will actually never
see it as x + x.

Reply via email to