Not at all, or same as elephants
To imagine a T-Rex cavalry we can start with an analog. Elephants. The African bush elephant bull is 3.2–4 m (10–13 ft) with a weight of 4,700–6,048 kg (10,362–13,334 lb). The T-Rex is larger, with an estimated 4,6-6 m (15-19,5ft) and 5,000-7,000 kilograms (11,000 to 15,500). So there is some overlap, though in general the t-rex is bigger. At these sizes it might surprise you that it isn't that much bigger. Especially if the T-Rex is walking, where it'll lower it's body. You can imagine the average T-Rex as the largest elephants to roam the planet. Elephants were used in warfare, so it starts off great.
It starts looking as a great choice. Elephants were used for charging enemy ranks, scattering troops and instilling fear. The T-Rex can do all of the above. It has a big bite to boot, which can be more effective in instilling fear than trampling. We need to talk about the downsides however.
A T-Rex can raise and lower it's body. This makes it more difficult to create appropriate riding gear. It'll need to account for a huge shift in angle of the back. You can get around it with more training, ordering the dinosaur around like an attack dog. Regardless of solutions in riding gear or other, it becomes more complex.
Charging the enemy also can become difficult. An elephant has four legs and is a stable platform. If one is injured in a fight, like trampling a soldier and some part of the armour pierces the flesh, it can still get away. A T-Rex has only two legs for locomotion. An injury could immediately take it out of the fight, as well as be a death sentence.
This leads great to the next point. Predators are cowards. They generally only attack if there is a high likelihood of not getting injured. An injured elephant can limp to a tree and eat. Any predator will be unable to hunt. This makes a T-Rex a poor choice as cavalry. Predators in general are genetically programmed to avoid injury to a much higher extreme than a herbivore. Where being sick or injured can be dangerous for any mammal, the predators will have a much harder time. Social groups like lions or humans can still engage in risky behaviour, though you'll still see that they try to have overwhelming odds to win the fight. If it needs to charge or bite some infantry bristling with spears, would they really do it? It is likely hard to train that into the animals and the return could be relatively slim.
It is also difficult to give armour. It's abdomen and head are likely targets. If you armour those, you'll put weights on one side of a creature balancing on two feat. In other words, it's not balanced any more. An elephant in contrast can be armoured from one side, allowing much higher survivability.
The final nail in the coffin isn't even battle itself. It is simple logistics. A T-Rex requires a load of premium food. Meat is more difficult to get than leaves or grass and can be eaten by your soldiers. You'll need a special supply chain just to keep them fed. As they say, logistics win battles and not armies. Severely complicating your logistics, not to mention increasing cost by a huge margin, is never a winning strategy. Simply put, they lose wars by just existing in your army.
Conclusion
You could conceivably have a niche for a T-Rex in a battle. It is big, powerful and scary. However, their role is done better by a humble elephant. They are less powerful and scary. They still are better at trampling, training and logistics, can be better armoured, are able to forage off the land, require less expensive gear to ride and are in general less expensive overall to maintain in and outside of war. A T-Rex as cavalry is a great rule of cool. It is bad regardless.