[llvm] [llvm][NFC] Refactor autoupdater's 'c' intrinsics (PR #73333)

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


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

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.

>From 94b47613c88826b6af2f63041180336875de2d27 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Fri, 24 Nov 2023 09:30:08 -0500
Subject: [PATCH] [llvm][NFC] Refactor autoupdater's 'c' intrinsics

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.
---
 llvm/lib/IR/AutoUpgrade.cpp | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

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;



More information about the llvm-commits mailing list