  Magnesium dihydride ($\mgh$) stores 7.7 weight % hydrogen, but it suffers
from a high thermodynamic stability and slow (de)hydrogenation kinetics.
Alloying Mg with lightweight transition metals (TM = Sc, Ti, V, Cr) aims at
improving the thermodynamic and kinetic properties. We study the structure and
stability of Mg$_x$TM$_{1-x}$H$_2$ compounds, $x=[0$-1], by first-principles
calculations at the level of density functional theory. We find that the
experimentally observed sharp decrease in hydrogenation rates for $x\gtrsim0.8$
correlates with a phase transition of Mg$_x$TM$_{1-x}$H$_2$ from a fluorite to
a rutile phase. The stability of these compounds decreases along the series Sc,
Ti, V, Cr. Varying the transition metal (TM) and the composition $x$, the
formation enthalpy of Mg$_x$TM$_{1-x}$H$_2$ can be tuned over the substantial
range 0-2 eV/f.u. Assuming however that the alloy Mg$_x$TM$_{1-x}$ does not
decompose upon dehydrogenation, the enthalpy associated with reversible
hydrogenation of compounds with a high magnesium content ($x=0.75$) is close to
that of pure Mg.
