By fall 621, however, Dou's general Liu Heita had risen against Tang rule and regained most of former Xia territory. At that point, Yuchi was not under Li Shimin's command, as he was fighting invading Eastern Tujue forces at Yuan Prefecture (原州, roughly modern Guyuan, Ningxia). In 622, when Li Shimin went to fight Liu Heita, however, Yuchi was again under his command, and once, when Li Shimin tried to aid another Tang general, Li Shiji, Liu had him surrounded. Li Shimin was saved only after Yuchi fought his way in to rescue him. Li Shimin was later able to defeat Liu Heita, forcing him to flee to Eastern Tujue. (Later that year, however, Liu Heita would return and again take over former Xia territory, only to be later defeated by Li Shimin's older brother Li Jiancheng the Crown Prince.) Yuchi also then followed Li Shimin in his campaign against Liu Heita's ally Xu Yuanlang. In 623, he was again fighting invading Tujue forces, this time at Shuo Prefecture, and then in 624 at Long Prefecture (隴州, modern western Baoji, Shaanxi).