[clang] [llvm] [RFC][CodeGen] Add generic target feature checks for intrinsics (PR #201470)

Sameer Sahasrabuddhe via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 24 07:59:04 PDT 2026


================
@@ -25,6 +26,23 @@ TargetSubtargetInfo::TargetSubtargetInfo(
 
 TargetSubtargetInfo::~TargetSubtargetInfo() = default;
 
+bool TargetSubtargetInfo::isIntrinsicSupported(unsigned IntrinsicID,
+                                               const CallBase &CB) const {
+  StringRef RequiredFeatures = Intrinsic::getRequiredTargetFeatures(
+      static_cast<Intrinsic::ID>(IntrinsicID));
+
+  if (RequiredFeatures.empty())
+    return true;
+
+  if (RequiredFeatures == Intrinsic::CustomTargetFeatures)
+    return isIntrinsicSupportedByTarget(IntrinsicID, CB);
+
+  auto [It, Inserted] = IntrinsicSupportCache.try_emplace(IntrinsicID);
+  if (Inserted)
+    It->second = checkFeatureExpression(RequiredFeatures);
----------------
ssahasra wrote:

Related to my comment elsewhere about `$custom`, what if we _always_ do this:
```
  It->second = checkFeatureExpression(RequiredFeatures) && isIntrinsicSupportedByTarget(IntrinsicID, CB);
```
Essentially, if the required features are present, then always give the target a chance to deny support. That would make the `$custom` keyword unnecessary?


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


More information about the cfe-commits mailing list