Calculations of equilibrium properties of dense matter predict that at subnuclear densities nuclei can be rodlike or slablike. To investigate whether transitions between phases with nonspherical nuclei can occur during the collapse of a star, we perform quantum molecular dynamic simulations of the compression of dense matter. We have succeeded in simulating the transitions between rodlike and slablike nuclei and between slablike nuclei and cylindrical bubbles. Our results strongly suggest that nonspherical nuclei can be formed in the inner cores of collapsing stars.