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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=114074

--- Comment #8 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #7)
> I think this is ivopts bug (or at least that pass introduces UB into the IL
> that wasn't there before).
> In particular on the c <= 0 guarded edge it adds
>    <bb 8> [local count: 105119324]:
> +  _26 = b.1_13 + -2147483648;
> +  _1 = (unsigned int) _26;
> +  _8 = (unsigned int) _14;
> +  ivtmp.17_11 = _8 + 2147483648;
> where b.1_13 at runtime is -2147483647 and both b.1_13 and _26 have int type.
> So, the addition invokes UB.  Given that previously all that was there was
> (a + b) + 2147483647, nothing was known about b's range, only about a + b,
> so I think it certainly should have been unsigned _26:
>   _26 = (unsigned int) b.1_13;
>   _1 = _26 + 2147483648;

I guess this is one of the more long-standing SCEV issues, we analyze the
evolution of the loop PHI as:

(get_scalar_evolution
  (scalar = _18)
  (scalar_evolution = {_14, +, b.1_13 + -2147483648(OVF)}_1))

and from that

(get_scalar_evolution
  (scalar = _5)
  (scalar_evolution = {_14 - -2147483648, +, b.1_13 + -2147483648(OVF)}_1))
)

IVOPTs in the end selects

Selected IV set for loop 1 at t.c:8, 10 avg niters, 1 IVs:
Candidate 8:
  Depend on inv.exprs: 1
  Var befor: ivtmp.17_22
  Var after: ivtmp.17_21
  Incr POS: before exit test
  IV struct:
    Type:       unsigned int
    Base:       (unsigned int) _14 + 2147483648
    Step:       (unsigned int) (b.1_13 + -2147483648(OVF))
    Biv:        N
    Overflowness wrto loop niter:       Overflow

but it's really the association done by SCEV where things go downhill from.
I think this is another instance of PR114074 and friends.

Reply via email to