SHANGHAI (AP) — Although Roger Federer finally won a match in straight sets at this year's Shanghai Masters, it didn't save him any energy.

The defending champion reached the semifinals Friday by beating eighth-seeded Kei Nishikori 6-4, 7-6 (4). His first two matches both went three sets.

"It was the same length, actually, as all three of my matches went the same length basically, an hour and 52 (minutes)," Federer said. "So you see, two sets sometimes doesn't tell the truth."

Federer finished the match with 10 aces and landed an impressive 71 percent of his first serves. He went up a break at the start of the second set, but then trailed 4-1 in the tiebreaker.

"I was happy to get out in two," Federer said. "I somehow got it done. I think I can be very happy with my level of play this week."

Federer, a two-time champion in Shanghai, will next face 13th-seeded Borna Coric. The Croat defeated Matthew Ebden 7-5, 6-4.

"He's really improved his game, stepping up into the court, goes for his shots more than he used to," Federer said of Coric. "He good in defense now, he has a transition game now, and a solid serve. I've always played him when he's playing well, but I'll hope I can take it to him."

Earlier, fourth-seeded Alexander Zverev secured a spot in next month's ATP Finals with a 6-4, 6-4 quarterfinal win over Kyle Edmund.

Zverev is the fifth player to qualify for the season-ending tournament in London, joining Federer, Rafael Nadal, Novak Djokovic and Juan Martin del Potro in the eight-player field.

"Obviously it's great to finally officially make it and obviously be part of the eight best again, which is an elite group, which is kind of the goal for everyone at the beginning of the season," Zverev said.

Zverev will next play second-seeded Djokovic in the semifinals. The Wimbledon and U.S. Open champion, who is looking to win a record fourth Shanghai title, defeated seventh-seeded Kevin Anderson 7-6 (1), 6-3.

Zverev won his only encounter against Djokovic in the 2017 Rome final.

"It was a different surface," Djokovic said of their previous match. "I wasn't, I feel like, playing as well as I'm playing today.

"But also, he has improved a lot, and he has established himself as a top player. It's going to be definitely a close match."

Anderson had a chance to take an early lead against Djokovic but he overhit a forehand on set point in the 12th game of the match. Djokovic didn't give the South African another opportunity.

Zverev, who improved to 4-0 against Edmund, saved the one break point he faced and took advantage of the two break points he earned.

The victory gave the 21-year-old Zverev a tour-leading 49th match win of the year. Dominic Thiem, who lost his opening match this week, is in second place with 48 match wins this season.

"It means a lot because I have kind of played only the biggest tournaments," Zverev said. "Obviously I don't want to stop here. There is still a lot more tennis going on till the end of the year. I'm in semifinals now, and I obviously don't want to be satisfied just yet."

_

More AP tennis: https://apnews.com/tag/apf-Tennis and https://twitter.com/AP_Sports