This allows compilers to optimize by reordering code before/after a loop. Without this, the compiler would only be allowed to move code around the loop if it could prove the loop terminates. By contrast, with this UB, the compiler is allowed to do this move if the loop is not doing IO or accessing volatile memory locations.
I'd also note that this particular footgun only exists in C++, the C standard allows loops that never terminate and never do IO or volatile memory access.
I'd also note that this particular footgun only exists in C++, the C standard allows loops that never terminate and never do IO or volatile memory access.