[llvm] [InferAddressSpaces] Handle unconverted ptrmask (PR #140802)
Robert Imschweiler via llvm-commits
llvm-commits at lists.llvm.org
Thu May 22 05:50:13 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();
----------------
ro-i wrote:
> I'm not sure I understand why this is necessary. I suppose the issue is we're speculatively assuming the value will need a rewrite, and then need to roll back.
Yes, `operandWithNewAddressSpaceOrCreatePoison` can create a poison value and append the old operand to `PoisonUsesToFix` right before `TTI->rewriteIntrinsicWithAddressSpace` is called.
> We're not actually making any target specific assumptions there, beyond integral pointers. Can we just move that code here, and check that the address spaces are integral?
In `TTI->rewriteIntrinsicWithAddressSpace`, `TM.isNoopAddrSpaceCast` is called. Since we don't have direct access to the TargetMachine in InferAddressSpaces, I would either need to generate a way to call `TM.isNoopAddrSpaceCast` from InferAddressSpaces, or keep the call to `TTI->rewriteIntrinsicWithAddressSpace`.
What do you think?
https://github.com/llvm/llvm-project/pull/140802
More information about the llvm-commits
mailing list