On 13/05/2024 14:42, Rademacher Lars via Gcc-help wrote: > Dear all, > > I am having the problem, that since GCC 8 in the following code the if-section is optimized away for any optimization levels above 0. > But actually for a negative value of 'a', the value of 'ret' will overflow and thus 'ret' will be < 0, so the if-section cannot be optimized away. > > #include <stdint.h> > int32_t foo(int32_t a) > { > int32_t ret = INT32_MAX - a; > > if (ret < 0) { > ret -= 50; > } > > return ret; > } > > I am guessing, this is due to the fact, that signed integer overflow is undefined behavior in C/C++ and thus the compiler assumes this is prevented. Can you confirm this? Correct. > Can you give a hint, if this is a correct assumption and why this was introduced? > > Which part of GCC 8 release notes represents this optimization? https://gcc.gnu.org/gcc-8/changes.html Just look for 'signed integer overflow'. R.