As noted in PR39973 and D55558:
https://bugs.llvm.org/show_bug.cgi?id=39973
...this is a partial implementation of a fold that we do as an IR canonicalization in instcombine:
// extelt (binop X, Y), Index --> binop (extelt X, Index), (extelt Y, Index)
We want to have this in the DAG too because as we can see in some of the test diffs (reductions), the pattern may not be visible in IR.
Given that this is already an IR canonicalization, any backend that would prefer a vector op over a scalar op is expected to already have the reverse transform in DAG lowering (not sure if that's a realistic expectation though).
There's an ARM test diff that shows that we also have a reverse transform in IR in CGP. I'm not sure what to make of that. Isn't the updated asm better than the existing code for that test?
Note that I changed some existing regression tests leading up to this patch trying to preserve their intent. Let me know if we need to do any more of that for the remaining diffs here. These were the preliminary commits (and so those tests are not affected by this patch):
rL349160
rL349163
rL349164
rL349166
rL349176
rL349177