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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
          Component|c                           |middle-end
      Known to work|                            |4.9.4
   Target Milestone|---                         |5.5
            Summary|Incorrect constant result   |[5/6/7 Regression]
                   |for summing loop inserted   |Incorrect constant result
                   |                            |for summing loop inserted

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed, caused by SCCP (or SCEV/niter analysis):

Analyzing # of iterations of loop 1
  exit condition [-2147483645, + , 1] != 2147483647
  bounds on difference of bases: 4294967292 ... 4294967292
  result:
    # of iterations 4294967292, bounded by 4294967292
Replacing uses of: sum_11 with: 2147483648

while it computes correctly the evolution of the sum IV:

{0, +, {2147483650, +, 1}_1}_1

somehow the exit PHI value is computed as 2147483648 by
compute_overall_effect_of_inner_loop on that IV + x

{2147483650, +, {2147483651, +, 1}_1}_1

number of latch executions is computed as 4294967292.

We run into chrec_evaluate with the above where binominal coeff evaluation
checks for overflow in the signed type but the computation in chrec_evaluate
doing

      arg0 = fold_build2 (MULT_EXPR, type,
                          CHREC_LEFT (chrec), binomial_n_k);

has no such checks.  On the GCC 4.9 branch we fail:

(chrec_apply
  (varying_loop = 1
)
  (chrec = {2147483650, +, {2147483651, +, 1}_1}_1)
  (x = 4294967292)
  (res = scev_not_known))
not replacing:
  sum_2 = PHI <sum_4(3)>

thus this is a regression with the wide-int conversion somehow.

Reply via email to