[llvm] [PowerPC] improve performance on the isNan and !isNan function in case of -ffp-model=strict" (PR #215587)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 13:06:12 PDT 2026
================
@@ -11978,6 +11978,36 @@ SDValue PPCTargetLowering::LowerIS_FPCLASS(SDValue Op,
return getDataClassTest(LHS, Category, Dl, DAG, Subtarget);
}
+// PPCTargetLowering::expandIS_FPCLASS is PPC-specific pre-legalization
+// override.
+//
+// SelectionDAGBuilder calls this early (before type legalization) whenever
+// IS_FPCLASS is not Legal or Custom for the operand type.
+//
+// We replace fcNan/~fcNan on f32/f64
+// with a floating-point self-comparison (SETUO / SETO), producing
+// cleaner code on all PPC scalar FP targets. All other masks are delegated to
+// the generic expander.
+SDValue PPCTargetLowering::expandIS_FPCLASS(EVT ResultVT, SDValue Op,
+ FPClassTest Test, SDNodeFlags Flags,
+ const SDLoc &Dl,
+ SelectionDAG &DAG) const {
+ EVT VT = Op.getValueType();
+ FPClassTest NotNan = static_cast<FPClassTest>(fcAllFlags & ~fcNan);
+
+ // Only intercept fcNan / ~fcNan on scalar f32/f64 for non-P9 targets.
+ if ((VT != MVT::f32 && VT != MVT::f64) || (Test != fcNan && Test != NotNan))
+ return TargetLowering::expandIS_FPCLASS(ResultVT, Op, Test, Flags, Dl, DAG);
+
+ // SelectCC(Op, Op, 1, 0, SETUO) -> 1 if NaN, 0 otherwise (fcNan)
+ // SelectCC(Op, Op, 1, 0, SETO) -> 1 if not NaN, 0 otherwise (~fcNan)
+ // This is pre-legalization: ResultVT (i1 or i32) will be type-legalized
+ // normally, so no need to branch on useCRBits() here.
----------------
RolandF77 wrote:
nit: should probably note that P9 will go here too if not userCRBits since then it is not custom.
https://github.com/llvm/llvm-project/pull/215587
More information about the llvm-commits
mailing list