[PATCH] D125600: [SelectionDAGBuilder] Pass fast math flags to VP SDNodes.

Yeting Kuo via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 14 00:59:04 PDT 2022


fakepaper56 created this revision.
Herald added subscribers: luke957, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
Herald added a project: All.
fakepaper56 requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, MaskRay.
Herald added a project: LLVM.

The patch also makes float VPCmpIntrinsic be class of FPMathOperator.
But LLParser will still output error if the use of float VPCmpIntrinsic
is before the declaration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125600

Files:
  llvm/include/llvm/IR/Operator.h
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/RISCV/rvv/fast-math-flags-vp.ll


Index: llvm/test/CodeGen/RISCV/rvv/fast-math-flags-vp.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/RISCV/rvv/fast-math-flags-vp.ll
@@ -0,0 +1,12 @@
+; RUN: llc -mtriple=riscv64 -mattr=+v -target-abi=lp64d < %s
+
+; Note: If the declartion moved after its use, there is still an error:
+; 'fast-math-flags specified for call without floating-point scalar or vector return type'.
+declare <vscale x 8 x i1> @llvm.vp.fcmp.nxv8f64(<vscale x 8 x double>, <vscale x 8 x double>, metadata, <vscale x 8 x i1>, i32)
+
+define <vscale x 8 x i1> @fcmp_uno_vf_swap_nxv8f64(<vscale x 8 x double> %va, double %b, <vscale x 8 x i1> %m, i32 zeroext %evl) {
+  %elt.head = insertelement <vscale x 8 x double> poison, double %b, i32 0
+  %vb = shufflevector <vscale x 8 x double> %elt.head, <vscale x 8 x double> poison, <vscale x 8 x i32> zeroinitializer
+  %v = call fast <vscale x 8 x i1> @llvm.vp.fcmp.nxv8f64(<vscale x 8 x double> %vb, <vscale x 8 x double> %va, metadata !"uno", <vscale x 8 x i1> %m, i32 %evl)
+  ret <vscale x 8 x i1> %v
+}
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -7546,13 +7546,9 @@
 
   ISD::CondCode Condition;
   CmpInst::Predicate CondCode = VPIntrin.getPredicate();
-  bool IsFP = VPIntrin.getOperand(0)->getType()->isFPOrFPVectorTy();
-  if (IsFP) {
-    // FIXME: Regular fcmps are FPMathOperators which may have fast-math (nnan)
-    // flags, but calls that don't return floating-point types can't be
-    // FPMathOperators, like vp.fcmp. This affects constrained fcmp too.
+  if (auto *FPMO = dyn_cast<FPMathOperator>(&VPIntrin)) {
     Condition = getFCmpCondCode(CondCode);
-    if (TM.Options.NoNaNsFPMath)
+    if (FPMO->hasNoNaNs() || TM.Options.NoNaNsFPMath)
       Condition = getFCmpCodeWithoutNaN(Condition);
   } else {
     Condition = getICmpCondCode(CondCode);
@@ -7581,6 +7577,11 @@
 
   auto IID = VPIntrin.getIntrinsicID();
 
+  SDNodeFlags SDFlags;
+  if (auto *FPMO = dyn_cast<FPMathOperator>(&VPIntrin))
+    SDFlags.copyFMF(*FPMO);
+  SelectionDAG::FlagInserter FlagsInserter(DAG, SDFlags);
+
   if (const auto *CmpI = dyn_cast<VPCmpIntrinsic>(&VPIntrin))
     return visitVPCmp(*CmpI);
 
Index: llvm/include/llvm/IR/Operator.h
===================================================================
--- llvm/include/llvm/IR/Operator.h
+++ llvm/include/llvm/IR/Operator.h
@@ -20,6 +20,7 @@
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/FMF.h"
 #include "llvm/IR/Instruction.h"
+#include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Value.h"
 #include "llvm/Support/Casting.h"
@@ -317,6 +318,9 @@
     case Instruction::PHI:
     case Instruction::Select:
     case Instruction::Call: {
+      if (auto *VPCmp = dyn_cast<VPCmpIntrinsic>(V))
+        return VPCmp->getOperand(0)->getType()->isFPOrFPVectorTy();
+
       Type *Ty = V->getType();
       while (ArrayType *ArrTy = dyn_cast<ArrayType>(Ty))
         Ty = ArrTy->getElementType();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125600.429414.patch
Type: text/x-patch
Size: 3176 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220514/651e682f/attachment-0001.bin>


More information about the llvm-commits mailing list