As discussed in D70852, currently LLVM may introduce calls to fmin/fmax into programs that originally did not have any dependency against libm, potentially causing failures at link time.
This patch attempts to solve this issue by adding code to TargetLowering::expandFMINNUM_FMAXNUM to expand FMINNUM/FMAXNUM to a compare+select sequence instead of the libcall. This is done only if the node is marked as "nnan". In this case, the expansion to compare+select is always correct. This also catches all cases where the FMINNUM/FMAXNUM was synthesized by LLVM; this is also only done in the nnan case.
I think this is an acceptable check of the FMF, but the reasoning is subtle. If we synthesized the intrinsic in IR, it required 'nsz' for the fcmp/select because the original code using fcmp can produce a different result for -0.0.
And that is because the intrinsics have this clause:
"If the operands compare equal, returns a value that compares equal to both operands. This means that fmin(+/-0.0, +/-0.0) could return either -0.0 or 0.0"
So once we have the intrinsic, the 'nsz' behavior becomes implicit.
And since we're not checking for 'nsz' explicitly in this expansion, that means that we may be transforming code that originally had the libcall in source to inline code (the intrinsic was not created by InstCombine without 'nsz').
But that's probably a good optimization for a target that is expanding these nodes anyway?
To not lose an optimization opportunity, I think we need to add 'nsz' to the setFlags() call under here. Or avoid this complexity and check for 'nsz' in the first place.