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] Refactor autoupdater's 'c' intrinsics #73333

Merged
merged 1 commit into from
Nov 30, 2023

Conversation

urnathan
Copy link
Contributor

With these three intrinsics it's probable faster to check the number of arguments first and then check the names. We can also handle ctlz and cttz in the same block.

With these three intrinsics it's probable faster to check the number
of arguments first and then check the names.  We can also handle ctlz
and cttz in the same block.
@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

With these three intrinsics it's probable faster to check the number of arguments first and then check the names. We can also handle ctlz and cttz in the same block.


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

1 Files Affected:

  • (modified) llvm/lib/IR/AutoUpgrade.cpp (+13-12)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 63c4b2c71299900..e6ff864a9140118 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -971,19 +971,20 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
     break;
   }
   case 'c': {
-    if (Name.starts_with("ctlz.") && F->arg_size() == 1) {
-      rename(F);
-      NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz,
-                                        F->arg_begin()->getType());
-      return true;
-    }
-    if (Name.starts_with("cttz.") && F->arg_size() == 1) {
-      rename(F);
-      NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz,
-                                        F->arg_begin()->getType());
-      return true;
+    if (F->arg_size() == 1) {
+      Intrinsic::ID ID = StringSwitch<Intrinsic::ID>(Name)
+                             .StartsWith("ctlz.", Intrinsic::ctlz)
+                             .StartsWith("cttz.", Intrinsic::cttz)
+                             .Default(Intrinsic::not_intrinsic);
+      if (ID != Intrinsic::not_intrinsic) {
+        rename(F);
+        NewFn = Intrinsic::getDeclaration(F->getParent(), ID,
+                                          F->arg_begin()->getType());
+        return true;
+      }
     }
-    if (Name.equals("coro.end") && F->arg_size() == 2) {
+
+    if (F->arg_size() == 2 && Name.equals("coro.end")) {
       rename(F);
       NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::coro_end);
       return true;

@arsenm arsenm merged commit 770dc47 into llvm:main Nov 30, 2023
5 checks passed
@urnathan urnathan deleted the push/autoupdater-c branch December 1, 2023 23:41
Guzhu-AMD pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Dec 7, 2023
Local branch amd-gfx 8ac93c2 Merged main:8b9a6af4504a into amd-gfx:30878b6d9320
Remote branch main 770dc47 [llvm][NFC] Refactor autoupdaters c intrinsics (llvm#73333)
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