diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h --- a/llvm/include/llvm/IR/Operator.h +++ b/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(V)) + return VPCmp->getOperand(0)->getType()->isFPOrFPVectorTy(); + Type *Ty = V->getType(); while (ArrayType *ArrTy = dyn_cast(Ty)) Ty = ArrTy->getElementType(); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/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(&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(&VPIntrin)) + SDFlags.copyFMF(*FPMO); + SelectionDAG::FlagInserter FlagsInserter(DAG, SDFlags); + if (const auto *CmpI = dyn_cast(&VPIntrin)) return visitVPCmp(*CmpI); diff --git a/llvm/test/CodeGen/RISCV/rvv/fast-math-flags-vp.ll b/llvm/test/CodeGen/RISCV/rvv/fast-math-flags-vp.ll new file mode 100644 --- /dev/null +++ b/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 @llvm.vp.fcmp.nxv8f64(, , metadata, , i32) + +define @fcmp_uno_vf_swap_nxv8f64( %va, double %b, %m, i32 zeroext %evl) { + %elt.head = insertelement poison, double %b, i32 0 + %vb = shufflevector %elt.head, poison, zeroinitializer + %v = call fast @llvm.vp.fcmp.nxv8f64( %vb, %va, metadata !"uno", %m, i32 %evl) + ret %v +}