This extends the foldOpIntoPhi code used when visiting a freeze user of a phi to allow any non-undef/poison operand as opposed to only non-undef/poison constants.
While this works, I'm not sure this is the right way to solve this problem. We're replacing a very cheap check with a bounded search of each phi operand, which has potential compile time implications. (@nikic - Could you help quantify?)
This routine is fairly limited. I went looking for a stronger routine (because really we're just folding the phi away when inst-simplify can prove there's an existing value for all but one operand), but was shocked not to find one (anywhere). I've got a toy binop test case that shows we entirely miss the corresponding opportunity at O3.
I'm really curious on others take here.