If you are American pay and more taxes in Spain than you would owe in the US, you are most likely collecting unusable foreign tax credits, and in the event that you move back to the US, it would be unlikely that these would come to much use.
So what you’d really like would be some way to shift taxation of income from the future to now, so that you can apply your US foreign tax credits now. At the same time, you’d like to do it in such a way that Spain doesn’t tax you at a higher rate as well.
If you are lucky enough to work for a company that grants restricted employee stock awards, there is a mechanism available for you.
Normally, you are given the rights to the stock, but your ability to actually sell it vests over some period of time (usually four or five years). You usually pay taxes on the stock as it vests (although in Spain you can reduce your income somewhat by not selling part of it for three years).
Section 83b of the US tax code lets you pay taxes on a portion of the restricted stock you receive NOW, as opposed to when it vests. This means that you can choose an amount is taxed to match the excess foreign tax credits you have, so that at the end of the year, your Spanish and US tax liabilities are exactly the same (and you still owe 0 to the US).
If you do end up moving back to the US and continue to work for your company, you now are able to vest that part of the stock tax free, so in the end, you can recuperate most of the extra taxes you paid while you were in the US.
A word of caution: In the case you quit or get fired, you don’t get a refund, but it’s unlikely that you’d be able to use the excess foreign tax credits for much, so it’s not that big of a loss.