Fix insert_node_here! if called at the end of the IR (#39021)
This method was throwing an error when called after the compaction
had processes the last instruction in the IR (with reverse affinity).
This currently can't, because we never use this method after compacting
a terminal instruction (inlining uses it to split BBs), but can after
the new code in #37849, so fix the bug now. Forward port from #37849.