Skip to content

[TTI][RISCV] Deduplicate type-based VP costing of vpcmp/vpcast #117520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

LiqinWeng
Copy link
Contributor

Refered to: #115983

@llvmbot
Copy link
Member

llvmbot commented Nov 25, 2024

@llvm/pr-subscribers-backend-risc-v

Author: LiqinWeng (LiqinWeng)

Changes

Refered to: #115983


Full diff: https://github.com/llvm/llvm-project/pull/117520.diff

2 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/BasicTTIImpl.h (+15)
  • (modified) llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp (+34-33)
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index d3d68ff1c6ed2b..c226e414d193b5 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -1618,6 +1618,21 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
           return thisT()->getArithmeticInstrCost(*FOp, ICA.getReturnType(),
                                                  CostKind);
         }
+        if (VPCastIntrinsic::isVPCast(ICA.getID())) {
+          return thisT()->getCastInstrCost(
+              *FOp, ICA.getReturnType(), ICA.getArgTypes()[0],
+              TTI::CastContextHint::None, CostKind);
+        }
+        if (VPCmpIntrinsic::isVPCmp(ICA.getID())) {
+          // We can only handle vp_cmp intrinsics with underlying instructions.
+          if (ICA.getInst()) {
+            assert(FOp);
+            auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
+            return thisT()->getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0],
+                                               ICA.getReturnType(),
+                                               UI->getPredicate(), CostKind);
+          }
+        }
       }
 
       std::optional<Intrinsic::ID> FID =
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 45576d515112dd..d82f9c120e81c4 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -1113,39 +1113,40 @@ RISCVTTIImpl::getIntrinsicInstrCost(const IntrinsicCostAttributes &ICA,
     return getArithmeticInstrCost(*FOp, ICA.getReturnType(), CostKind);
     break;
   }
-  // vp int cast ops.
-  case Intrinsic::vp_trunc:
-  case Intrinsic::vp_zext:
-  case Intrinsic::vp_sext:
-  // vp float cast ops.
-  case Intrinsic::vp_fptoui:
-  case Intrinsic::vp_fptosi:
-  case Intrinsic::vp_uitofp:
-  case Intrinsic::vp_sitofp:
-  case Intrinsic::vp_fptrunc:
-  case Intrinsic::vp_fpext: {
-    std::optional<unsigned> FOp =
-        VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
-    assert(FOp.has_value() && !ICA.getArgTypes().empty());
-    return getCastInstrCost(*FOp, RetTy, ICA.getArgTypes()[0],
-                            TTI::CastContextHint::None, CostKind);
-    break;
-  }
-
-  // vp compare
-  case Intrinsic::vp_icmp:
-  case Intrinsic::vp_fcmp: {
-    Intrinsic::ID IID = ICA.getID();
-    std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
-    // We can only handle vp_cmp intrinsics with underlying instructions.
-    if (!ICA.getInst())
-      break;
-
-    assert(FOp);
-    auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
-    return getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0], ICA.getReturnType(),
-                              UI->getPredicate(), CostKind);
-  }
+  // // vp int cast ops.
+  // case Intrinsic::vp_trunc:
+  // case Intrinsic::vp_zext:
+  // case Intrinsic::vp_sext:
+  // // vp float cast ops.
+  // case Intrinsic::vp_fptoui:
+  // case Intrinsic::vp_fptosi:
+  // case Intrinsic::vp_uitofp:
+  // case Intrinsic::vp_sitofp:
+  // case Intrinsic::vp_fptrunc:
+  // case Intrinsic::vp_fpext: {
+  //   std::optional<unsigned> FOp =
+  //       VPIntrinsic::getFunctionalOpcodeForVP(ICA.getID());
+  //   assert(FOp.has_value() && !ICA.getArgTypes().empty());
+  //   return getCastInstrCost(*FOp, RetTy, ICA.getArgTypes()[0],
+  //                           TTI::CastContextHint::None, CostKind);
+  //   break;
+  // }
+
+  // // vp compare
+  // case Intrinsic::vp_icmp:
+  // case Intrinsic::vp_fcmp: {
+  //   Intrinsic::ID IID = ICA.getID();
+  //   std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);
+  //   // We can only handle vp_cmp intrinsics with underlying instructions.
+  //   if (!ICA.getInst())
+  //     break;
+
+  //   assert(FOp);
+  //   auto *UI = cast<VPCmpIntrinsic>(ICA.getInst());
+  //   return getCmpSelInstrCost(*FOp, ICA.getArgTypes()[0],
+  //   ICA.getReturnType(),
+  //                             UI->getPredicate(), CostKind);
+  // }
   case Intrinsic::vp_select: {
     Intrinsic::ID IID = ICA.getID();
     std::optional<unsigned> FOp = VPIntrinsic::getFunctionalOpcodeForVP(IID);

@LiqinWeng LiqinWeng changed the title [TTI][RISCV] Deduplicate type-based VP costing of vmcp/vcast [TTI][RISCV] Deduplicate type-based VP costing of vpcmp/vpcast Nov 25, 2024
Copy link
Contributor

@lukel97 lukel97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks. I think this will also fix the costing of llvm.vp.ptrtoint and llvm.vp.inttoptr. Would you mind adding some tests for these too?

@LiqinWeng LiqinWeng merged commit dd7aabf into llvm:main Nov 26, 2024
8 checks passed
@LiqinWeng LiqinWeng deleted the add-vp-costing branch December 11, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants