[llvm] [llvm][NFC] Autoupdater AMD intrinsic detection (PR #73331)

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 24 06:29:14 PST 2023


https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/73331

Here's a refactor of the amd autoupdater, using prefix stripping and commonizing the replacement fndecl creation.

>From b32a0af51f8565d4a090d859c4f9d25d85f3bbec Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Wed, 23 Aug 2023 19:38:20 -0400
Subject: [PATCH] [llvm][NFC] Autoupdater AMD intrinsic detection

---
 llvm/lib/IR/AutoUpgrade.cpp | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 63c4b2c71299900..4a9b8e10b43e3f3 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -945,29 +945,30 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
       return true;
 
     if (Name.consume_front("amdgcn.")) {
-      if (Name == "alignbit") {
-        // Target specific intrinsic became redundant
-        NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::fshr,
-                                          {F->getReturnType()});
-        return true;
-      }
 
-      if (Name.starts_with("atomic.inc") || Name.starts_with("atomic.dec")) {
-        // This was replaced with atomicrmw uinc_wrap and udec_wrap, so there's no
-        // new declaration.
-        NewFn = nullptr;
+      Intrinsic::ID ID = StringSwitch<Intrinsic::ID>(Name)
+                             .Case("alignbit", Intrinsic::fshr)
+                             .StartsWith("ldexp.", Intrinsic::ldexp)
+                             .Default(Intrinsic::not_intrinsic);
+      if (ID != Intrinsic::not_intrinsic) {
+        // Some target-specific intrinsics became redundant.
+        SmallVector<Type *, 2> Tys;
+        Tys.push_back(F->getReturnType());
+        if (ID == Intrinsic::ldexp)
+          Tys.push_back(F->getArg(1)->getType());
+        NewFn = Intrinsic::getDeclaration(F->getParent(), ID, Tys);
         return true;
       }
 
-      if (Name.starts_with("ldexp.")) {
-        // Target specific intrinsic became redundant
-        NewFn = Intrinsic::getDeclaration(
-          F->getParent(), Intrinsic::ldexp,
-          {F->getReturnType(), F->getArg(1)->getType()});
-        return true;
-      }
+      if (Name.consume_front("atomic."))
+        if (Name.starts_with("inc") || Name.starts_with("dec")) {
+          // These were replaced with atomicrmw uinc_wrap and udec_wrap, so
+          // there's no new declaration.
+          NewFn = nullptr;
+          return true;
+        }
+      break; // No other 'amdgcn.*'
     }
-
     break;
   }
   case 'c': {



More information about the llvm-commits mailing list