Then as the mainland market developed they increased their mainland footprint as a hedge (makes it harder for the Chinese government to attack TSMC, though as we've seen from Alibaba, Xi appears happy to "move fast and break things"). That did in fact forestall investment in a competitor until recently.
They have also been expanding outside China-Taiwan, distributing their capacity and developing support in the USA and Europe. Worst case (actual shooting war between China and Taiwan) they would have a lot to fall back on.
Hon Hai has followed the same geostrategy (to even greater extreme) with its Foxconn subsidiary.