Transforms occasionally want to insert an instruction directly after the definition point of a value. This involves quite a few different edge cases, e.g. for phi nodes the next insertion point is not the next instruction, and for invokes and callbrs its not even in the next block. Additionally, the insertion point may not exist at all if catchswitch is involved.
We currently reimplement this logic in a few places, and usually get it wrong in one way or another. I've added two tests to demonstrate issues.
This adds a general Instruction::getInsertionPointAfterDef() API to reuse the (hopefully correct) logic.
Can you change this to getInsertionPointAfterDef? That reads more clearly to me.