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

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 20 09:15:23 PDT 2023


urnathan created this revision.
urnathan added reviewers: nikic, arsenm.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
urnathan requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

Here's a refactor of `case 'c':`, Both `cttz` and `ctlz` need the same upgrading, so they can be handled together. But we do split the mnemonic in the middle, rather than at a `.`.  Even though we know the first letter is `'c'`, and so could have done `Name[1] == 't'`, IMHO a `consume_front("ct")` conveys intent more clearly.


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,23 @@
 
     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':
+    if (Name.consume_front("ct")) {
+      if (F->arg_size() == 1) {
+        Intrinsic::ID ID = StringSwitch<Intrinsic::ID>(Name)
+                               .StartsWith("lz.", Intrinsic::ctlz)
+                               .StartsWith("tz.", 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; // No other 'ct*'
     }
     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.551850.patch
Type: text/x-patch
Size: 1490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230820/fe2c3193/attachment.bin>


More information about the llvm-commits mailing list