[llvm] b6c220d - [llvm][NFC] Adjust mem fn auto upgrade detection

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 5 14:30:07 PDT 2023


Author: Nathan Sidwell
Date: 2023-08-05T17:29:04-04:00
New Revision: b6c220da021941899c7049e8104a0ed3946f1c41

URL: https://github.com/llvm/llvm-project/commit/b6c220da021941899c7049e8104a0ed3946f1c41
DIFF: https://github.com/llvm/llvm-project/commit/b6c220da021941899c7049e8104a0ed3946f1c41.diff

LOG: [llvm][NFC] Adjust mem fn auto upgrade detection

AutoUpgrade detection of memcpy and memmove is almost
identical. Commonize the code path.

Reviewed By: jroelofs

Added: 
    

Modified: 
    llvm/lib/IR/AutoUpgrade.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 4182b4af2d9ce6..698b6257f513bf 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -1102,21 +1102,18 @@ static bool UpgradeIntrinsicFunction1(Function *F, Function *&NewFn) {
     // Updating the memory intrinsics (memcpy/memmove/memset) that have an
     // alignment parameter to embedding the alignment as an attribute of
     // the pointer args.
-    if (Name.startswith("memcpy.") && F->arg_size() == 5) {
-      rename(F);
-      // Get the types of dest, src, and len
-      ArrayRef<Type *> ParamTypes = F->getFunctionType()->params().slice(0, 3);
-      NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::memcpy,
-                                        ParamTypes);
-      return true;
-    }
-    if (Name.startswith("memmove.") && F->arg_size() == 5) {
-      rename(F);
-      // Get the types of dest, src, and len
-      ArrayRef<Type *> ParamTypes = F->getFunctionType()->params().slice(0, 3);
-      NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::memmove,
-                                        ParamTypes);
-      return true;
+    if (unsigned ID = StringSwitch<unsigned>(Name)
+                          .StartsWith("memcpy.", Intrinsic::memcpy)
+                          .StartsWith("memmove.", Intrinsic::memmove)
+                          .Default(0)) {
+      if (F->arg_size() == 5) {
+        rename(F);
+        // Get the types of dest, src, and len
+        ArrayRef<Type *> ParamTypes =
+            F->getFunctionType()->params().slice(0, 3);
+        NewFn = Intrinsic::getDeclaration(F->getParent(), ID, ParamTypes);
+        return true;
+      }
     }
     if (Name.startswith("memset.") && F->arg_size() == 5) {
       rename(F);


        


More information about the llvm-commits mailing list