[PATCH] D157763: [llvm][NFC] Adjust AutoUpdater 'masked' address-space access

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 15:28:58 PDT 2023


urnathan created this revision.
urnathan added reviewers: jroelofs, bruno.
Herald added a subscriber: hiraditya.
Herald added a project: All.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

In working on memcpy et al, I noticed that many of the AutoUpdater's pattern matchers suffer the same issues of
(a) not commonizing similar handling of the intrinsic creation, and
(b) repeatedly checking for the same prefix, and
(c) if the name matched, but other conditions failed, it would fall through to check a different prefix (which could not match).

This one handles the 'masked.$FOO' intrinsics to avoid those deficiences.

Part 1 in a series of N.


https://reviews.llvm.org/D157763

Files:
  llvm/lib/IR/AutoUpgrade.cpp


Index: llvm/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -1053,51 +1053,34 @@
     break;
   }
   case 'm': {
-    if (Name.startswith("masked.load.")) {
-      Type *Tys[] = { F->getReturnType(), F->arg_begin()->getType() };
-      if (F->getName() !=
-          Intrinsic::getName(Intrinsic::masked_load, Tys, F->getParent())) {
-        rename(F);
-        NewFn = Intrinsic::getDeclaration(F->getParent(),
-                                          Intrinsic::masked_load,
-                                          Tys);
-        return true;
-      }
-    }
-    if (Name.startswith("masked.store.")) {
-      auto Args = F->getFunctionType()->params();
-      Type *Tys[] = { Args[0], Args[1] };
-      if (F->getName() !=
-          Intrinsic::getName(Intrinsic::masked_store, Tys, F->getParent())) {
-        rename(F);
-        NewFn = Intrinsic::getDeclaration(F->getParent(),
-                                          Intrinsic::masked_store,
-                                          Tys);
-        return true;
-      }
-    }
-    // Renaming gather/scatter intrinsics with no address space overloading
-    // to the new overload which includes an address space
-    if (Name.startswith("masked.gather.")) {
-      Type *Tys[] = {F->getReturnType(), F->arg_begin()->getType()};
-      if (F->getName() !=
-          Intrinsic::getName(Intrinsic::masked_gather, Tys, F->getParent())) {
-        rename(F);
-        NewFn = Intrinsic::getDeclaration(F->getParent(),
-                                          Intrinsic::masked_gather, Tys);
-        return true;
-      }
-    }
-    if (Name.startswith("masked.scatter.")) {
-      auto Args = F->getFunctionType()->params();
-      Type *Tys[] = {Args[0], Args[1]};
-      if (F->getName() !=
-          Intrinsic::getName(Intrinsic::masked_scatter, Tys, F->getParent())) {
-        rename(F);
-        NewFn = Intrinsic::getDeclaration(F->getParent(),
-                                          Intrinsic::masked_scatter, Tys);
-        return true;
+    StringRef MaskPfx = "masked.";
+    if (Name.startswith(MaskPfx)) {
+      // Renaming masked intrinsics with no address space overloading
+      // to the new overload, which includes an address space.
+      Intrinsic::ID ID =
+          StringSwitch<Intrinsic::ID>(Name.substr(MaskPfx.size()))
+              .StartsWith("load.", Intrinsic::masked_load)
+              .StartsWith("store.", Intrinsic::masked_store)
+              .StartsWith("gather.", Intrinsic::masked_gather)
+              .StartsWith("scatter.", Intrinsic::masked_scatter)
+              .Default(Intrinsic::not_intrinsic);
+      if (ID != Intrinsic::not_intrinsic) {
+        const auto *FT = F->getFunctionType();
+        SmallVector<Type *, 2> Tys;
+        if (ID == Intrinsic::masked_load || ID == Intrinsic::masked_gather)
+          // Loading operations overload on the return type.
+          Tys.push_back(FT->getReturnType());
+        Tys.push_back(FT->getParamType(0));
+        if (ID == Intrinsic::masked_store || ID == Intrinsic::masked_scatter)
+          // Store operations overload on the stored type.
+          Tys.push_back(FT->getParamType(1));
+        if (F->getName() != Intrinsic::getName(ID, Tys, F->getParent())) {
+          rename(F);
+          NewFn = Intrinsic::getDeclaration(F->getParent(), ID, Tys);
+          return true;
+        }
       }
+      break; // No other 'masked.*'
     }
     // Updating the memory intrinsics (memcpy/memmove/memset) that have an
     // alignment parameter to embedding the alignment as an attribute of


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157763.549536.patch
Type: text/x-patch
Size: 3691 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230811/7991b94e/attachment.bin>


More information about the llvm-commits mailing list