The scalarizer pass seems to be inserting instructions in-between PHI nodes or debug intrinsics that end up staying at the end of the pass, resulting in malformed IR and violating assumptions.
This patch adds a check to make sure the extractelement instructions that it adds are correctly placed after all PHI nodes and debug intrinsics.
nit: static is redundant in anonymous namespaces