arsenm added a comment. I discovered that the libcall already does this nnan compare + select canonicalization (although I don't get the rationale for it, the opposite seems preferable). Are you still working on this patch? https://reviews.llvm.org/D21137