> This is a common misconception (or poor way of phrasing it, sorry). Compiler implementers don't go looking for instances of undefined behavior in a program with the goal of optimizing it in some way. There is little value in optimizing invalid code. The opposite is the case.
Compilers do deliberately look to optimize loops with signed counters by exploiting UB to assume that they will never wrap.