As mentioned in D72643, we'd like to be able to assert that any select of equivalent constants has been removed before we're deep into InstCombine.
But there's a loophole in that assertion for vectors with undef elements that don't match exactly.
This patch should close that gap. If we have undefs, we can't safely propagate those unless both constants elements for that lane are undef.
I'm having a bit of a hard time convincing myself that this is always correct. In particular, the relationship between isElementWiseEqual(), which is based on ConstantExpr::getICmp() and this code, which is based on simple identity comparison, is not entirely clear. If the vector includes complex constant expressions, and ConstantExpr::getICmp() manages to fold that code while the identity comparison fails, this would trigger an assertion failure here. Or is there an invariant that this cannot happen?