This is a transform suggested in PR37463:
This makes sense for IR because we should always have equal or better analysis for a scalar binop vs. a vector binop. It can also lead to follow-on transforms/simplifications as seen in some of the div/rem tests that change opcodes.
It's not as clearly a win for codegen (where keeping everything as vector ops might be better for perf), but I haven't seen any regressions yet, and it should be possible to reverse this if needed.
A couple of details worth pointing out:
- This does not need to be limited with isSafeToSpeculativelyExecute() like the related shuffle transforms in this function. We're doing strictly less work by only operating on 1 lane of a vector, so there's no opportunity for executing on unknown bits. So div/rem are included in the diffs.
- As noted in the last code comment, we can't just insert into an undef vector constant because that could be more undef than the original code was. But we'll probably end up inserting into an undef vector anyway in most cases because that's what the constants simplify to (as seen in the test results).