<i>&gt;But I can&#x27;t understand why e.g. use of an oversized shift amounts are UB</i><p>Suppose a CPU, when shifting a 32 bit register, uses only the lower 5 bits of the shift count. Then shifting a register by 32 will be a shift by 0, i.e. a no-op (instead of clearing the register). The compiler would have to generate additional code to correctly handle this which would be slower. So it was decided to make oversized shifts UB.