[llvm] [NVPTX] Cleanup NVPTXLowerArgs, simplifying logic and improving alignment propagation (PR #180286)

Drew Kersnar via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 13:49:44 PST 2026


================
@@ -644,57 +598,52 @@ static bool runOnKernelFunction(const NVPTXTargetMachine &TM, Function &F) {
   // integers, followed by intotoptr. We may want to mark those as global, too,
   // but only if the loaded integer is used exclusively for conversion to a
   // pointer with inttoptr.
-  auto HandleIntToPtr = [](Value &V) {
-    if (llvm::all_of(V.users(), [](User *U) { return isa<IntToPtrInst>(U); })) {
-      SmallVector<User *, 16> UsersToUpdate(V.users());
-      for (User *U : UsersToUpdate)
-        markPointerAsGlobal(U);
-    }
-  };
   if (TM.getDrvInterface() == NVPTX::CUDA) {
     // Mark pointers in byval structs as global.
-    for (auto &B : F) {
-      for (auto &I : B) {
-        if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
-          if (LI->getType()->isPointerTy() || LI->getType()->isIntegerTy()) {
-            Value *UO = getUnderlyingObject(LI->getPointerOperand());
-            if (Argument *Arg = dyn_cast<Argument>(UO)) {
-              if (Arg->hasByValAttr()) {
-                // LI is a load from a pointer within a byval kernel parameter.
-                if (LI->getType()->isPointerTy())
-                  markPointerAsGlobal(LI);
-                else
-                  HandleIntToPtr(*LI);
-              }
-            }
+    for (auto &I : instructions(F)) {
+      auto *LI = dyn_cast<LoadInst>(&I);
+      if (!LI)
+        continue;
+
+      if (LI->getType()->isPointerTy() || LI->getType()->isIntegerTy()) {
+        Value *UO = getUnderlyingObject(LI->getPointerOperand());
+        if (Argument *Arg = dyn_cast<Argument>(UO)) {
+          if (Arg->hasByValAttr()) {
+            // LI is a load from a pointer within a byval kernel parameter.
+            if (LI->getType()->isPointerTy())
+              markPointerAsGlobal(LI);
+            else
+              handleIntToPtr(*LI);
           }
         }
       }
     }
+
+    for (Argument &Arg : F.args())
+      if (Arg.getType()->isIntegerTy())
+        handleIntToPtr(Arg);
----------------
dakersnar wrote:

nit: maybe include a comment on this function? Not super clear to me what exactly this is handling.

https://github.com/llvm/llvm-project/pull/180286


More information about the llvm-commits mailing list