[llvm] [InferAddressSpaces] Handle unconverted ptrmask (PR #140802)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 22 06:20:31 PDT 2025


================
@@ -669,17 +666,24 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
     // Technically the intrinsic ID is a pointer typed argument, so specially
     // handle calls early.
     assert(II->getIntrinsicID() == Intrinsic::ptrmask);
+    const Use &PtrArgUse = II->getArgOperandUse(0);
     Value *NewPtr = operandWithNewAddressSpaceOrCreatePoison(
-        II->getArgOperandUse(0), NewAddrSpace, ValueWithNewAddrSpace,
-        PredicatedAS, PoisonUsesToFix);
+        PtrArgUse, NewAddrSpace, ValueWithNewAddrSpace, PredicatedAS,
+        PoisonUsesToFix);
     Value *Rewrite =
         TTI->rewriteIntrinsicWithAddressSpace(II, II->getArgOperand(0), NewPtr);
     if (Rewrite) {
       assert(Rewrite != II && "cannot modify this pointer operation in place");
       return Rewrite;
     }
-
-    return nullptr;
+    // Leave the ptrmask as-is and insert an addrspacecast after it.
+    Instruction *AddrSpaceCast = new AddrSpaceCastInst(II, NewPtr->getType());
+    AddrSpaceCast->insertAfter(II->getIterator());
+    AddrSpaceCast->setDebugLoc(II->getDebugLoc());
+    // If we generated a poison operand for the ptr argument, remove it.
+    if (!PoisonUsesToFix->empty() && PoisonUsesToFix->back() == &PtrArgUse)
+      PoisonUsesToFix->pop_back();
----------------
arsenm wrote:

You can equivalently use TTI->isNoopAddrSpaceCast

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


More information about the llvm-commits mailing list