Federer advanced to their 47th career meeting by beating Kei Nishikori 6-4, 6-4, his sixth straight win against the Japanese player.
Chasing his 100th career title after winning the Swiss Indoors last Sunday, the 20-time Grand Slam champion was hardly troubled. He saved a break point with a sharp volley at the net when serving for the set at 5-4 and then broke Nishikori at the start of the second set to take firm control.
Federer has won this tournament only once, in 2011, and has not played here since 2015. He was given a huge ovation by the crowd after his win.
Now he has to find a way past Djokovic, the Wimbledon and US Open champion who has beaten Federer in their past three meetings and leads him 24-22 overall.
Djokovic, who is guaranteed to take the No. 1 ranking on Monday, struggled on his serve for much of the first set.
Cilic had chances to break him in the fifth and seventh games and finally did so in the ninth when Djokovic hit a backhand long.
An ace gave Cilic set point, and he took it when Djokovic sent a backhand wide.
Djokovic broke for 3-1 in the second set and did not look back.
In the third set, a Cilic crosscourt forehand winner saw him break a for 2-1 lead.
Djokovic broke his racket in frustration and then broke Cilic straight back, after which the momentum shifted back in his favor, as Cilic lost to him for the 16th time in 18 meetings.
"It was a very intense match," Djokovic said. "I was kind of going up and down. I'm really pleased to overcome this kind of challenge."
It was also Djokovic's 21st consecutive win since losing to Stefanos Tsitsipas in the third round of the Rogers Cup in August.
The Austrian served out the match and clinched victory on his first match point when Sock hit a big forehand long.
"I'm in the semifinals of a Masters 1000 only for the fourth time," Thiem said. "It means a lot for me because I didn't do too well in the previous years in this part of the season. So it's something really special to reach the semifinals."
Thiem broke the American in the fifth game of the third set and then showed good composure to save two break points of his own at 15-40 in the eighth game.
"We always have to be aware of getting broken here. Somehow a lot of breaks are happening," Thiem said. "It's a little bit comfortable to return here."
The sixth-seeded Thiem, meanwhile, next faces unseeded Karen Khachanov of Russia in their first career meeting.
Khachanov, who won the Kremlin Cup in Moscow last month, broke fourth-seeded Alexander Zverev's serve six times in a 6-1, 6-2 win.
Zverev had treatment on his right shoulder late in the first set and made a string of unforced errors. He took exception to some comments made in Khachanov's box and spoke to his opponent at the end of the first set.
"I told him my shoulder is hurting and that his uncle, or something, that he's going a bit crazy," Zverev said. "I told him to tell him to keep it down a little bit because he was going a little bit too much over the edge."