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

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 25 05:03:35 PST 2023


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

>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 1/2] [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': {

>From f003571241ae51a1bbff22759e970051fb72eb82 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Sat, 25 Nov 2023 08:03:17 -0500
Subject: [PATCH 2/2] Just atomic

---
 llvm/lib/IR/AutoUpgrade.cpp | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 4a9b8e10b43e3f3..da7570471563f9e 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -945,30 +945,33 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
       return true;
 
     if (Name.consume_front("amdgcn.")) {
-
-      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);
+      if (Name == "alignbit") {
+        // Target specific intrinsic became redundant
+        NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::fshr,
+                                          {F->getReturnType()});
         return true;
       }
 
-      if (Name.consume_front("atomic."))
+      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.atomic.*'
+      }
+
+      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;
+      }
       break; // No other 'amdgcn.*'
     }
+
     break;
   }
   case 'c': {



More information about the llvm-commits mailing list