The faction led by Li eventually formed the
Tang dynasty while Li himself became historically known as "
Emperor Gaozu of Tang". Cheng was appointed as a military officer under Li Yuan's second son,
Li Shimin. He fought for the Tang Empire against rival warlords such as Wang Shichong,
Song Jingang () and
Dou Jiande, who were either defeated or surrendered to Tang. Cheng was enfeoffed as the "Duke of Su" () for his contributions in battle. In 624, when there was an ongoing rivalry between Li Shimin and his eldest brother,
Li Jiancheng (the Crown Prince), over the succession to their father's throne, Li Jiancheng became very suspicious and distrustful of Cheng. Emperor Gaozu appointed Cheng as the Prefect of Kang Prefecture (康州; around present-day
Zhaoqing,
Guangdong), effectively sending him far away from the capital,
Chang'an (present-day
Xi'an,
Shaanxi). Cheng told Li Shimin, "Great Prince, if you lose your left and right arms, you will not survive long. I will not leave you, even if it means I will die." On 2 July 626, Cheng joined Li Shimin in assassinating Li Jiancheng and his fourth brother,
Li Yuanji (the Prince of Qi), at the
Xuanwu Gate Incident, after which Li Shimin became the new Crown Prince. He was appointed as a "Right Guard Commander to the Crown Prince" () and subsequently promoted to "Right Martial Guard Senior General" () and awarded 700 taxable households in his dukedom. ==Service under Emperor Taizong==