This patch fixes a verification error with -verify-machineinstrs while expanding __tls_get_addr by not creating ADJCALLSTACKUP and ADJCALLSTACKDOWN if there is another ADJCALLSTACKUP in this basic block since nesting ADJCALLSTACKUP/ADJCALLSTACKDOWN is not allowed.
Here, ADJCALLSTACKUP and ADJCALLSTACKDOWN are created as a fence for instruction scheduling to avoid _tls_get_addr is scheduled before mflr in the prologue (https://bugs.llvm.org//show_bug.cgi?id=25839). So if another ADJCALLSTACKUP exists before _tls_get_addr, we do not need to create a new ADJCALLSTACKUP.
With this patch and two previous patches (https://reviews.llvm.org/D34208 and https://reviews.llvm.org/D34209), I successfully compiled LLVM+CLANG with -verify-machineinstrs on ppc64le Linux.
If the ADJCALLSTACKDOWN instruction is guaranteed to occur before any of the "TLS" pseudos in a basic block, that should be mentioned in a comment here. If on the other hand it isn't guaranteed to happen, we can form adjacent ADJCALLSTACKDOWN/ADJCALLSTACKUP blocks.
I don't imagine that's a problem, but it is somewhat inconsistent here...
What I mean is that if this loop encounters an ADJCALLSTACKDOWN which is followed by an ADJCALLSTACKUP, we will still not emit the instructions for the subsequent TLS instructions. I am not sure if that is a problem or not.
So the crux of what I'm saying here is this:
Will not add the adjustments. Whereas this will (for all of the TLS instructions):
And this will add the adjustments only for the TLS instructions that appear before the stack adjustments that were already there: