[llvm] [RISCV][CostModel] Estimate cost of llvm.vector.reduce.fmaximum/fminimum (PR #80697)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 21 00:58:27 PDT 2024


================
@@ -1002,50 +1002,48 @@ RISCVTTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty,
   }
 
   if (IID == Intrinsic::maximum || IID == Intrinsic::minimum) {
-    SmallVector<unsigned, 5> SplitOps;
     SmallVector<unsigned, 3> Opcodes;
     InstructionCost ExtraCost = 0;
     switch (IID) {
     case Intrinsic::maximum:
       if (FMF.noNaNs()) {
-        SplitOps = {RISCV::VFMAX_VV};
         Opcodes = {RISCV::VFREDMAX_VS, RISCV::VFMV_F_S};
       } else {
-        SplitOps = {RISCV::VMFEQ_VV, RISCV::VMERGE_VVM, RISCV::VMFEQ_VV,
-                    RISCV::VMERGE_VVM, RISCV::VFMAX_VV};
         Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMAX_VS,
                    RISCV::VFMV_F_S};
-        // Cost of Canonical Nan
+        // Cost of Canonical Nan + branch
         // lui a0, 523264
         // fmv.w.x fa0, a0
-        ExtraCost = 2;
+        Type *DstTy = Ty->getScalarType();
+        const unsigned EltTyBits = DL.getTypeSizeInBits(DstTy);
+        Type *SrcTy = IntegerType::getIntNTy(DstTy->getContext(), EltTyBits);
+        ExtraCost = 1 +
+                    getCastInstrCost(Instruction::UIToFP, DstTy, SrcTy,
+                                     TTI::CastContextHint::None, CostKind) +
+                    getCFInstrCost(Instruction::Br, CostKind);
       }
       break;
 
     case Intrinsic::minimum:
       if (FMF.noNaNs()) {
-        SplitOps = {RISCV::VFMIN_VV};
         Opcodes = {RISCV::VFREDMIN_VS, RISCV::VFMV_F_S};
       } else {
-        SplitOps = {RISCV::VMFEQ_VV, RISCV::VMERGE_VVM, RISCV::VMFEQ_VV,
-                    RISCV::VMERGE_VVM, RISCV::VFMIN_VV};
         Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMIN_VS,
                    RISCV::VFMV_F_S};
-        // Cost of Canonical Nan
+        // Cost of Canonical Nan + branch
         // lui a0, 523264
         // fmv.w.x fa0, a0
-        ExtraCost = 2;
+        Type *DstTy = Ty->getScalarType();
+        const unsigned EltTyBits = DL.getTypeSizeInBits(DstTy);
----------------
lukel97 wrote:

Nit, I think `Ty->getScalarSizeInBits()` does the same thing

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


More information about the llvm-commits mailing list