[PATCH] D158369: [llvm][NFC] Refactor AutoUpgrade case 'c'

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 12:39:37 PDT 2023


urnathan updated this revision to Diff 552104.
urnathan added a comment.

Fair point.  How about this way round -- check the number of args before looking at the name.  IMHO That's likely to be more efficient. Of course common handling for a match is also good.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158369/new/

https://reviews.llvm.org/D158369

Files:
  llvm/lib/IR/AutoUpgrade.cpp


Index: llvm/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -915,21 +915,21 @@
 
     break;
   }
-  case 'c': {
-    if (Name.startswith("ctlz.") && F->arg_size() == 1) {
-      rename(F);
-      NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::ctlz,
-                                        F->arg_begin()->getType());
-      return true;
-    }
-    if (Name.startswith("cttz.") && F->arg_size() == 1) {
-      rename(F);
-      NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz,
-                                        F->arg_begin()->getType());
-      return true;
+  case 'c':
+    // cttz & ctlz intrinsics had another argument added.
+    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;
+      }
     }
     break;
-  }
   case 'd':
     if (Name.consume_front("dbg.")) {
       if (Name == "addr" || (Name == "value" && F->arg_size() == 4)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158369.552104.patch
Type: text/x-patch
Size: 1453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230821/65fdbb6f/attachment.bin>


More information about the llvm-commits mailing list