For code such as:
void f(int, int); void g() { f(1, 2); }
compiled for 32-bit X86 Linux at -Os, Clang would previously generate:
subl $12, %esp subl $8, %esp pushl $2 pushl $1 calll f addl $16, %esp addl $12, %esp retl
This patch fixes that by merging adjacent stack adjustments in eliminateCallFramePseudoInstr().
Unfortunately, this means that eliminateCallFramePseudoInstr() doesn't just replace a single machine instruction, but potentially erases the previous and/or next instruction as well. To allow the caller of eliminateCallFramePseudoInstr() to continue iterating, this patch makes the function return an iterator to the next instruction. This makes the code in PEI::replaceFrameIndices() much simpler.
Note that previously, replaceFrameIndices() would try to re-visit the instruction created by eliminateCallFramePseudoInstr(). That code was added in r36625, but I can't see any reason for it: the new instructions will obviously not be pseudo instructions, they will not have FrameIndex operands, and we have already accounted for the stack adjustment.
I would probably commit the change to replaceFrameIndices() and return type of eliminateCallFramePseudoInstr() separately.
Thanks for updating this too. 'void' here should probably be 'MachineBasicBlock::iterator'.