[llvm] [RISCV] Transform fcmp to is.fpclass (PR #120242)

Gergely Futo via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 17 11:49:49 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;
----------------
futog wrote:

Ok. Regarding the `InstCombinerImpl::foldIntrinsicIsFPClass`. For a back-end, where lowering the `fcmp` is not cheap, why is it profitable to do this transformation? It is done unconditionally as far as I see it.

https://github.com/llvm/llvm-project/pull/120242


More information about the llvm-commits mailing list