When Turkey's president visited Russia last summer, the sun shone as he shared ice cream and admired fighter jets with a friendly Vladimir Putin.

But ahead of Recep Tayyip Erdogan's visit to Moscow on Thursday, clouds have gathered with the pair in a standoff over Syria.

Fighting has intensified between Turkish troops and Moscow-backed regime forces in the northwestern Syrian province of Idlib.

The strongmen are entrenched on opposing sides and determined to hold their ground.

There are hopes the two leaders can at least agree a ceasefire at the talks. But Erdogan is unlikely to dent the Russian leader's resolve to back the regime in its offensive to recapture the last rebel stronghold in Syria.

For Putin, observers say, victory in Syria is not just political, it's personal.

"Putin's rise as a masterful strategist is associated with Syria," said Yury Barmin, a Middle East analyst at the Russian International Affairs Council, established to advise the Kremlin.

"Victory in Syria has become a matter of prestige for Russia -- and for Putin personally," he said.

Russia charged into Syria in late 2015 with an air campaign that turned the tide of the conflict in favour of the Damascus regime.

The intervention helped President Bashar al-Assad reclaim swathes of territory his forces had lost to Islamists and Western-backed opposition groups.

Putin, a former KGB agent who described the Soviet Union's collapse as a catastrophe, spied an opportunity to reclaim the Kremlin's former military glory and challenge the West.

Moscow has invested heavily in two bases on the Syrian coast -- the Tartus naval port and the Hmeimim air base -- so that Putin's warships and bombers can project military power throughout the Mediterranean, says Russian military analyst Pavel Felgenhauer.

"Russia is not that interested in Syria per se, but it's important to keep Assad in power because he guarantees that Russia has these bases," Felgenhauer said.

For Russian President Vladimir Putin, observers say, victory in Syria is not just political, it's personal
For Russian President Vladimir Putin, observers say, victory in Syria is not just political, it's personal SPUTNIK / Alexey DRUZHININ

Apart from anchoring Moscow's hold in the Mediterranean, the conflict in Syria has proved a valuable training ground for the military, with thousands of Russian troops gaining battlefield experience and hundreds of new weapons tested, says Dmitry Trenin, director of the Carnegie Moscow Center.

"It is a material example of what Russia can accomplish through a combination of military and diplomatic instruments," he says.

The conflict has personal resonance for Putin too, Trenin adds.

The Russian president rose to power 20 years ago during the Kremlin's war against insurgents in the Muslim-majority republic of Chechnya. Putin famously vowed to "waste them in the outhouse".

Rights groups have accused the Russian air force of war crimes in Syria with indiscriminate attacks on schools, hospitals and mosques, drawing comparisons with the destruction of the Chechen capital Grozny two decades ago.

With some 4,000 Russians travelling to join the ranks of Islamist groups in Iraq and Syria in recent years, Putin "has his own scores to settle with the terrorists", Trenin says.

"He came to prominence, and then to power, by defeating their predecessors in the North Caucasus."

Putin is also looking for a foreign policy victory that could boost his popularity in the face of approval ratings that have dropped because of economic stagnation.

The last time he scored a major win abroad -- the 2014 annexation of Crimea -- Putin's ratings jumped to nearly 90 percent.

Observers say that doesn't mean Putin won't be willing to make some compromise at Thursday's talks with Erdogan.

The two presidents are keen to avoid direct clashes that would jeopardise their trade or defence ties.

"Putin knows he has substantial military and political advantages over Erdogan", but will find a way to allow the Turkish leader to "back off while saving face", Trenin said.

Put more bluntly: "Putin is definitely seeking compromise with Turkey over Syria, but a compromise devised by Russia," Barmin said.