On Mon, 30 Nov 2026 09:22:07 GMT ant…@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
> Tim Rentsch <tr.1…@z991.linuxsc.com> writes:
> >ant…@mips.complang.tuwien.ac.at (Anton Ertl) writes: > >
> >> Thomas Koenig <tkoe…@netcologne.de> writes:
> >> > >> If the undefined behaviour nonsense would not be so sad, it > >> would be funny. The undefined behaviour advocates love to > >> claim that undefined behaviour allows more optimization than > >> defined behaviour, but in Comment 1 Richard Biener writes that > >> gcc does not perform this optimization because of undefined > >> behaviour. [...]
> > > >I suspect you are misunderstanding the meaning of RB's comment.
> > The comment in it's entirety is: > > |probably a duplicate, the GIMPLE level re-association pass doesn't > |consider signed integers (due to overflow UB) > > He uses the word "due" and not "because", but it's clear that the > reason he states for not performing this optimization is "overflow > UB". > > In the part of my posting that you deleted, I discuss why the gcc > maintainers may have decided not to reassociate in this case. >
> >The rules of C do not prohibit the optimization from being done. > >gcc does not perform the transformation because of a choice gcc > >has made about how code is compiled.
> > This does not change anything about the fact that gcc does not > reassociate the supposedly optimization-friendly overflow-UB integers, > while it does reassociate integers where overflow is defined to > perform modulo arithmetics.
Show me. I I spent dozens of minutes looking for such cases and did not find them. In all my tests gcc either generate poorly optimized latency bound code both for signed and unsigned integers or it generates better-looking code (I didn't measure if it really is faster) again, both for signed and unsigned integers. I never encountered the latter cases in the "open" code, only in loops and only in association with SIMDification.
> And it does not change the fact that > Richard Biener has written that gcc makes this choice "due to overflow > UB". > > - anton