This patch adds constant folding of insertelement instruction to undef value when index operand is constant and is not less than vector size or is undef.
InstCombine does not support this case, but I'm happy to add it there also if this change is accepted.
It might be nicer to do something like:
After the above comparison, we know that getZExtValue will succeed. This lets us simplify the loop below a little (i.e. Idx == i vs CIdx->equalsInt(i))