Ensure coro split pass only spills variables dominated by CoroBegin
Fixes https://bugs.llvm.org/show_bug.cgi?id=36578.
The old coro split code didn't run safety checks against certain
spillable variables; it would try to spill things that were not
dominated by CoroBegin.
This problem gets worse after the mem2reg
pass is run, as the code which checks that Arguments are safe to
spill is even more lax than the code which checks that
Instructions are safe to spill.
There's a test which checks two things:
First, that a store/load optimized away by mem2reg doesn't fail.
Second, if there is an allocator which takes a potentially
spillable argument, we have to check all of the other arguments
to that allocator to ensure there are no unspillable instructions
as well.
I believe llvm::cast<T> asserts if the cast to T fails, so this would assert for users that are not Instruction, such as Constant. In the future I'd recommend using dyn_cast, since it returns a false-y value if the cast fails:
Writing it this way would also remove the need for the second cast.