As discussed in the review thread for rL297026, this is actually 2 changes that would independently fix all of the test cases in the patch:
- Return undef in FoldConstantArithmetic for div/rem by 0.
- Move basic undef simplifications for div/rem (simplifyDivRem()) before foldBinopIntoSelect() as a matter of efficiency.
I can split it up, but I'm not sure yet how to expose the failures once either one of the fixes goes in.
I will handle the case of vectors with any zero element as a follow-up unless we want to do it all in one step. That change is the DAG sibling for D30665 + adding a check of vector elements to FoldConstantVectorArithmetic().
There are likely more improvements for undef handling needed for functions like isConstantSplatVector(), so I can also try to fix those too.