AW: optimizer discards sign information

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Ursprüngliche Nachricht-----
> Von: LIU Hao <lh_mouse@xxxxxxx>
> Gesendet: Mittwoch, 10. April 2024 11:51
> An: Xi Ruoyao <xry111@xxxxxxxxxxx>; Alexander Monakov
> <amonakov@xxxxxxxxx>; stefan@xxxxxxxxx
> Cc: gcc-help@xxxxxxxxxxx
> Betreff: Re: optimizer discards sign information
> 
> 在 2024-04-10 17:44, Xi Ruoyao 写道:
> > You only get a "different result" when an undefined behavior happens,
> > thus it **is** a valid point to say there is no wrong-code issue.
> >
> >> It's a real bug. There are many PRs on bugzilla.
> >
> > You may argue it's a missed-optimization, but we were discussing about
> > wrong-code or not.
> 
> Nobody in this thread has been thinking it's wrong code.
> 
> When there is no overflow, it's missed optimization. When there is an
> overflow, I don't care.
> 
> Do you agree?
> 
> 
> --
> Best regards,
> LIU Hao


Yes, there is an overflow when the value gets assigned to x

	u32 x = *a * *b;

And after that line of code, x is a valid unsigned int, no matter what value was assigned. And the compiler must not throw away that unsignedness.

Also an add can overflow:

u64 faa(int a, int b) {
    u32 x = a + b;
    u64 r = x;

And in this case the optimizer doesn't discard the variable x

With the multiplication the optimizer kills it:

int _5;

  _5 = _2 * _4;
  x_9 = (u32) _5;
  r_10 = (u64) x_9;

becomes:

  int _5;

  _5 = _2 * _4;
  r_10 = (u64) _5;

The cast to (u32) is an important information, which IMHO must not be discarded.


Regards

Stefan






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux