Comment

Comment by tpolzer

And indeed, clang is able to do it for unsigned, too: https://godbolt.org/z/36r1Maq7b

gcc doesn't seem to implement this optimization at all.

Technically it should be possible for the <=n case, too: An infinite loop is undefined behavior, so the compiler is allowed to assume it doesn't happen. But I guess (for good reasons) compiler writers are reluctant to exploit that too heavily (or it's just about ordering of optimization passes).

parent tpolzer 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton