foldOpIntoPhi() currently only folds operations into the phi if all but one operands constant-fold. The two exceptions to this are freeze and select, where we allow more general simplification.
This patch makes foldOpIntoPhi() generally simplification based and removes all the instruction-specific logic. We just try to simplify the instruction for each operand, and for the (potentially) one non-simplified operand, we move it into the new block with adjusted operands.
This fixes https://github.com/llvm/llvm-project/issues/57448, which was my original motivation for the change.
There is some barely measurable compile-time impact (http://llvm-compile-time-tracker.com/compare.php?from=5c5ac3490cb96bd187234226d26933ec0d92ed17&to=08ad1abbcaecf0986357498397d657506de38d13&stat=instructions), but it is in the 0.05% range, so I think this is fine.
This is an improvement, but it's not clear to me from the diffs or debug spew why it happened. Did you step through to look at that?