[llvm] [RISCV] Transform fcmp to is.fpclass (PR #120242)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 18:53:24 PST 2024
================
@@ -196,6 +199,42 @@ bool RISCVCodeGenPrepare::expandVPStrideLoad(IntrinsicInst &II) {
return true;
}
+// The 'fcmp uno/ord/oeq/une/ueq/one/ogt/oge/olt/ole x, 0.0' instructions are
+// equivalent to an FP class test. If the fcmp instruction would be custom
+// lowered or lowered to a libcall, use the is.fpclass intrinsic instead, which
+// is lowered by the back-end without a libcall.
+//
+// This basically reverts the transformations of
+// InstCombinerImpl::foldIntrinsicIsFPClass.
+bool RISCVCodeGenPrepare::visitFCmpInst(FCmpInst &Fcmp) {
+ const auto *TLI = ST->getTargetLowering();
+ const EVT VT = TLI->getValueType(*DL, Fcmp.getOperand(0)->getType());
+ const int ISDOpcode = TLI->InstructionOpcodeToISD(Fcmp.getOpcode());
+
+ auto LegalizeTypeAction = TLI->getTypeAction(Fcmp.getContext(), VT);
+ auto OperationAction = TLI->getOperationAction(ISDOpcode, VT);
+ if ((LegalizeTypeAction != TargetLoweringBase::TypeSoftenFloat &&
+ LegalizeTypeAction != TargetLoweringBase::TypeSoftPromoteHalf) ||
+ OperationAction == TargetLowering::Custom)
+ return false;
----------------
arsenm wrote:
fcmp is a better canonical form. More code will always understand fcmp than is.fpclass.
> fcmp is not cheap
This is certainly not universally true, and I would say is not the common case. If the target wants something else, that's for the backend to undo for its preferred form.
https://github.com/llvm/llvm-project/pull/120242
More information about the llvm-commits
mailing list