The world No. 3, playing for the first time in three weeks, suffered a shock defeat against 70th-ranked Spanish qualifier Albert Ramos-Vinolas, who has never won an ATP Tour title.
Federer had thrashed the 27-year-old in their only other meeting, on grass at Wimbledon in 2012, but found him to be a tougher opponent on the indoor hard court at Qi Zhong Stadium.
Ramos-Vinolas triumphed 7-6 (7-4) 2-6 6-3 in the second-round clash to set up a last-16 tie with French 16th seed Jo-Wilfried Tsonga.
As defending champion at the top-tier event
, Federer had the privilege of cooking up a pizza to serve in the players' restaurant.
"It's exciting," he said this week. "A lot of the pizzas were taken, the classic ones. I came up with one that I like -- figs, arugula salad, prosciutto, crème fraiche and extra mozzarella if you like."
The father of four also come up with a name for his trademark pizza. "It's the 'Figalicious,'" explained the 17-time grand slam winner.
"I don't know if you know, but the name is really important."
As tempting as Federer's concoction sounds, don't expect the 'Figalicious' to be delivered to your door any time soon.
It will only be available during the Chinese event, where signature pizzas have been served up for the last five years.
Tournament director Michael Luevano told Federer, who was eager to create his own pizza, he had to win the title for a chance to add his creation to the menu.
The 34-year-old -- who traditionally shares pizza with ball kids at his home event in Basel -- duly obliged by winning it for the first time in 2014, beating Frenchman Gilles Simon in the final.
As second seed in China, Federer had been hoping for the chance of revenge against world No. 1 Novak Djokovic, who beat him in September's U.S. Open final.
The Serbian, who defended his Beijing title on Sunday, beating Rafael Nadal in the final, is aiming to add to his 2012-13 successes in Shanghai.
As the reigning men's doubles champions, American twins Mike and Bob Bryan are also serving up a bespoke pizza in Shanghai.
Their "Twice as Nice" concoction will go down well with wheat-free Djokovic because it's a gluten-free crust topped with tomato sauce, dairy-free goat's cheese, chicken, red onions, red peppers, garlic and red chilli flakes.