Tax avoidance, as opposed to tax evasion, is not illegal although some might question its morality. Many organisations and individuals use the complexity of taxation laws to try to (legally) mitigate their taxation bills.
Tax avoidance is perfectly legitimate. If the government doesn't like it, the remedy is easy: close the loopholes and simplify the system.
And if companies that trade in the UK don't pay UK corporation tax (e.g. head office in Dublin), levy a turnover tax and/or a windfall tax on UK profits.