The timing of U.S. Defense Secretary Jim Mattis' trip to the Philippines this week couldn't have been better, coming just as it celebrated a victory against militants in Marawi City - with a critical dose of help from the U.S. military.

But as Mattis met President Rodrigo Duterte on Tuesday, five Russian warships were parked off the Philippines and Moscow was preparing to formally hand over thousands of assault rifles, a million rounds of ammunition and 20 army trucks at a public ceremony on Wednesday.

Duterte, known for his strident anti-American rhetoric, has made no secret of his plans to cultivate ties with America's rivals, Russia and China. Those efforts appear to be starting to bear fruit.

Just before he met Mattis, Duterte sat down with Russian Defense Minister Sergei Shoigu on Tuesday, who, like Mattis, was attending a gathering of Asian defence ministers north of Manila. Shoigu signed two military deals, including the procurement of unspecified equipment.

On Wednesday, Duterte was scheduled to visit a Russian anti-submarine ship, the Admiral Pantaleyev, docked in Manila.

U.S. Ambassador Sung Kim played down any U.S. concerns about Duterte's outreach to China and Russia and noted that the United States, a former colonial power, was the country's only treaty ally, with far deeper ties in the Philippines.

"I'm not really threatened by this notion that China or Russia are providing some military equipment to the Philippines," Kim told a small group of reporters travelling with Mattis.

"We have been providing very important equipment to the Philippines for many, many years. The fact that the Chinese and the Russians have provided some rifles, I'm not sure is really such a cause for concern for the United States."

Duterte's often profanity-laden tirades against the United States have become his trademark during his year-old presidency, and he has chided Washington for treating his country "like a dog," despite the longstanding U.S. assistance.

Still, Duterte's rhetoric has been inconsistent, and he warmly greeted visiting Secretary of State Rex Tillerson in August, calling himself a "humble friend" of the United States at the time.

On Tuesday, he cautiously kept to scripted dialogue at the start of his meeting with Mattis, as he welcomed him to the Philippines and spoke warmly of ties.

"I want to be (as) politically correct as possible and I want to be understood. So reading this speech will be good," he said before reporters were escorted out of the room.

Ahead of a visit by U.S. President Donald Trump to the Philippines, the U.S. envoy cited an improvement in "tone and substance" in bilateral ties over the 10 months since he's been in his post.

"President Duterte has made clear that even as he pursues improved relations with countries like China and Russia, he will continue to focus on making sure that the U.S.-Philippines alliance remains strong," Kim said.

MARAWI OPERATION

The same day that Mattis landed in the Philippines, Manila announced the end of five months of military operations in a southern city of Marawi held by pro-Islamic State rebels, after a fierce and unfamiliar urban war that marked the country's biggest security crisis in years.

The rebel occupation stunned a military inexperienced in urban combat and stoked wider concerns that Islamic State loyalists have gained influence among local Muslims and have ambitions to use the island of Mindanao as a base for operations in Southeast Asia.

Mattis, on his flight to the Philippines, commended Manila on the operation and on Tuesday discussed ways to deepen U.S.-Philippines military ties in talks with the Philippine defence minister.

"It was a tough fight," Mattis said during his flight, adding he thought the Philippines had sent "a very necessary message to the terrorists."

Kim said the U.S. military assistance made a "huge difference" in the battle in Marawi, particularly its intelligence support, including with the deployment of Gray Eagle and P-3 Orion aircraft.

"I think all of us were surprised by the extent of infiltration by the terrorists into Marawi City," he said.

"When you encounter a situation like that, you obviously need good intelligence to be able to target key areas and I think that's where our support was quite critical."

On Monday night, Philippine military chief General Eduardo Ano said the U.S. technical support "tilted the balance" because "we had a very hard grasp of the situation in the early days" until information flowed and helped defeat the militants.

The United States also provided information Islamic State leader Abu Bakr al-Baghdadi gave US$1.5 million in January for the attack on Marawi, Ano said.

But even on Marawi, Duterte has also credited U.S. rival China for its assistance.

Duterte said it was one of the 100 sniper rifles donated by China that fired the bullet that killed Isnilon Hapilon, Islamic State's "emir" in Southeast Asia, on Oct 16.

The ranger unit conducting the operation said the shot was fired from a heavier weapon mounted on an armoured vehicle.

Philippine Defense Secretary Delfin Lorenzana told reporters on Tuesday about the receipt of heavy equipment from China to help rebuild Marawi, and also noted the receipt of rifles and ammunition from Beijing. He expected to receive four fast boats from China before the end of the year.

The United States has for decades been the Philippines' defence treaty ally and its biggest source of hardware and training, providing about US$1 billion in equipment since 2000.