Re-applying r301766 with a fix to a typo and a regression test.
The log message for r301766 was:
InstructionSimplify: Canonicalize shuffle operands. NFC-ish. Summary: Apply canonicalization rules: 1. Input vectors with no elements selected from can be replaced with undef. 2. If only one input vector is constant it shall be the second one. This allows constant-folding to cover more ad-hoc simplifications that were in place and avoid duplication for RHS and LHS checks. There are more rules we may want to add in the future when we see a justification. e.g. mask elements that select undef elements can be replaced with undef.
Is the plan to actually do this canonicalization of constant to 2nd operand in InstCombine? If so, wouldn't it make sense to add a "commute" or "commuteMask" (this is what it's called in the DAG) function directly to ShuffleVectorInst and then use that here?