Or when undefined behavior is our friend.
The optimization can also be done for unsigned integers, it just has to be done slightly differently. https://ideone.com/EBwo8e
So undefined behavior isn't really enabling much more of an optimization here. It's just that the compiler misses this optimization for unsigned ints.
so why the compiler cannot use the more optimized, no loop method? unsigned has a well defined wrap around outcome.
so in the case of unsigned, what could be wrong if the compiler would be using the more optimized, no loop code gen? why exactly it says "I cant do it" ? in unsigned, you have a defined wrap around, right?
The optimization can also be done for unsigned integers, it just has to be done slightly differently. https://ideone.com/EBwo8e
So undefined behavior isn't really enabling much more of an optimization here. It's just that the compiler misses this optimization for unsigned ints.
so why the compiler cannot use the more optimized, no loop method? unsigned has a well defined wrap around outcome.
so in the case of unsigned, what could be wrong if the compiler would be using the more optimized, no loop code gen? why exactly it says "I cant do it" ? in unsigned, you have a defined wrap around, right?