The phase diagram of the carbon-hydrogen system is of great importance to planetary sciences, as hydrocarbons comprise a significant part of icy giant planets and are involved in reduced carbon-oxygen-hydrogen fluid in the deep Earth. Here we use resistively-and laser-heated diamond anvil cells to measure methane melting and chemical reactivity up to 80 GPa and 2,000 K. We show that methane melts congruently below 40 GPa. Hydrogen and elementary carbon appear at temperatures of 41,200 K, whereas heavier alkanes and unsaturated hydrocarbons (424 GPa) form in melts of 41,500 K. The phase composition of carbon-hydrogen fluid evolves towards heavy hydrocarbons at pressures and temperatures representative of Earth's lower mantle. We argue that reduced mantle fluids precipitate diamond upon re-equilibration to lighter species in the upwelling mantle. Likewise, our findings suggest that geophysical models of Uranus and Neptune require reassessment because chemical reactivity of planetary ices is underestimated.