[Bug c++/71753] Clamp function does not work with O3 optimization

2016-07-04 Thread lukasz.spintzyk at displaylink dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71753 --- Comment #6 from Łukasz Spintzyk --- I confirm changing the code to use unsigned int fixed the problem. Also there is no signed overflow errors. Thanks a lot.

[Bug c++/71753] Clamp function does not work with O3 optimization

2016-07-04 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71753 --- Comment #5 from Marc Glisse --- (In reply to Łukasz Spintzyk from comment #4) > Looking from this point of view is this really invalid? There is a perfectly valid way to write such code: "You need to use an unsigned type for this type of co

[Bug c++/71753] Clamp function does not work with O3 optimization

2016-07-04 Thread lukasz.spintzyk at displaylink dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71753 --- Comment #4 from Łukasz Spintzyk --- Yes, this code is utilizing overflow, but it is there for a reason to optimize the code and get rid of branches as they can slow down program execution. You can refer to http://locklessinc.com/articles/sat

[Bug c++/71753] Clamp function does not work with O3 optimization

2016-07-04 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71753 Andrew Pinski changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|---

[Bug c++/71753] Clamp function does not work with O3 optimization

2016-07-04 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71753 --- Comment #2 from Marc Glisse --- -fsanitize=undefined a.c:11:21: runtime error: signed integer overflow: 260 + 2147483392 cannot be represented in type 'int' You need to use an unsigned type for this type of computation.

[Bug c++/71753] Clamp function does not work with O3 optimization

2016-07-04 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71753 --- Comment #1 from Andrew Pinski --- Comment on attachment 38830 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38830 Code that reproduces the issue value + 0x7F00 Will overflow most of the time.