[llvm] [PowerPC] improve performance on the isNan and !isNan function in case of -ffp-model=strict" (PR #215587)
zhijian lin via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 18 11:48:51 PDT 2026
diggerlin wrote:
> Oh, I missed the part about strictfp. In that case, I still don't think codegen is the correct place to solve this. InstCombine can also make the transform, just using llvm.experimental.constraint.fcmp(s?)
1. InstCombine is run before the SelectionDAGBuilder::visitIntrinsicCall.
2. isNan(float x) is equal to @llvm.is.fpclass.f32(float %x, i32 3) is the same behaviours, InstCombine should not change the the behaviours of isNan(x).
3. In the source code for InstCombinerImpl::foldIntrinsicIsFPClass, it only handles the !IsStrict case. By the time SelectionDAGBuilder::visitIntrinsicCall runs, foldIntrinsicIsFPClass has already had its chance to fold llvm.is.fpclass(x, fcNan) into fcmp uno. If it folded the intrinsic (the non-strictfp case), visitIntrinsicCall never sees an is_fpclass intrinsic at all—it sees an fcmp. Only if the fold was skipped (because IsStrict=true or because the mask is fcSNan/fcQNan, which have no fcmp equivalents) does visitIntrinsicCall build an IS_FPCLASS node that eventually reaches LowerIS_FPCLASS.
4. according to https://llvm.org/docs/LangRef.html#llvm-experimental-constrained-fptrunc-intrinsic
` The quiet comparison operation performed by ‘llvm.experimental.constrained.fcmp’ will only raise an exception if either argument is a SNAN. The signaling comparison operation performed by ‘llvm.experimental.constrained.fcmps’ will raise an exception if either argument is a NAN (QNAN or SNAN).`
isNan(x) never raise a exception for both SNan and QNan , so isNan(x) can not convert to llvm.experimental.constraint.fcmp(s?)
5.If you happen to have a good solution for this, I'd really appreciate it if you could share it. Alternatively, if you believe codegen isn't the right place to address this, I'd be grateful if you could explain your reasoning. ?
https://github.com/llvm/llvm-project/pull/215587
More information about the llvm-commits
mailing list