This implements the same folding for SelectionDAG than what is present in InstCombine.
I haven't put a test yet, and it breaks the validation, but before fixing this I seek opinion on NaN handling here. InstCombine does not care and I don't really see why the same IR would be handled differently in the DAG than in InstCombine.
Is the third check supposed to be N2?