Roger Federer crashed out of the last 16 of the Shanghai Masters losing in three sets to world No42 Gael Monfils.