Skip to content
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

[llvm][NFC] Autoupdater AMD intrinsic detection #73331

Merged
merged 2 commits into from
Dec 1, 2023

Conversation

urnathan
Copy link
Contributor

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

@urnathan urnathan marked this pull request as ready for review November 24, 2023 19:49
@llvmbot
Copy link
Collaborator

llvmbot commented Nov 24, 2023

@llvm/pr-subscribers-llvm-ir

Author: Nathan Sidwell (urnathan)

Changes

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


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

1 Files Affected:

  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+19-18)
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': {

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

I feel like this one isn't an improvement. I don't think the alignbit and ldexp cases should be conflated. They don't really have any relation and different signatures.

@urnathan
Copy link
Contributor Author

You're right, I'd got too fixated on StringSwitch. Here's an update just addressing the 'atomic' ops, where the prefix check can help.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

I don't mind the change, but I personally probably wouldn't do it -- don't think that handling a common prefix for just two intrinsic really adds clarity. I'll leave it up to you.

@urnathan urnathan merged commit adc6b43 into llvm:main Dec 1, 2023
3 checks passed
@urnathan urnathan deleted the push/autoupdater-amd branch December 1, 2023 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants