An optimal semiclassical bound on certain commutators