Fix a bug where we were inserting a spill in between the PHIs in the beginning of the block.
Consider this fragment:
begin: %phi1 = phi i32 [ 0, %entry ], [ 2, %alt ] %phi2 = phi i32 [ 1, %entry ], [ 3, %alt ] %sp1 = call i8 @llvm.coro.suspend(token none, i1 false) switch i8 %sp1, label %suspend [i8 0, label %resume i8 1, label %cleanup] resume: call i32 @print(i32 %phi1)
Unless we are spilling the argument or result of the invoke, we were always inserting the spill immediately following the instruction.
The fix adds a check that if the spilled instruction is a PHI Node, select an appropriate insert point with getFirstInsertionPt() that
skips all the PHI Nodes and EH pads.
This will be a problem if this phi is in a catchswitch block created for MSVC EH. Is that something you worry about yet? You can make such a phi like this:
I'm not sure what you need to do to make this a coroutine as well, but maybe you can make a test case that way.
Anyway, this is totally something that doesn't need to be addressed in this change.