If we consider the Irish sandwich mechanism that was recently “stopped”, somehow that hasn’t materially affected any of the innumerable companies that were using it. As we saw in the Apple vs EU case, most practices might’ve never been actually legal either.
So my personal opinion is that (almost) all tax “optimization” is at the minimum immoral, but most likely illegal too.
Edit: This reminds me of the idea of temporarily embarrassed millionaires. Your personal optimization is not what I’m talking about - corporations have legal teams the size of SMBs lobbying/creating/looking for secret loopholes, and people are talking about public self service methods.