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

Robert Imschweiler via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 26 05:56:02 PDT 2025


================
@@ -153,23 +153,24 @@ class TargetTransformInfoImplBase {
 
   virtual bool isNoopAddrSpaceCast(unsigned, unsigned) const { return false; }
 
-  // Given an address space cast of the given pointer value, calculate the known
-  // bits of the source pointer in the source addrspace and the destination
-  // pointer in the destination addrspace.
   virtual std::pair<KnownBits, KnownBits>
-  computeKnownBitsAddrSpaceCast(unsigned FromAS, unsigned ToAS,
-                                const Value &PtrOp) const {
+  computeKnownBitsAddrSpaceCast(unsigned ToAS, const Value &PtrOp) const {
+    const Type *PtrTy = PtrOp.getType();
+    assert(PtrTy->isPtrOrPtrVectorTy() &&
+           "expected pointer or pointer vector type");
+    unsigned FromAS = PtrTy->getPointerAddressSpace();
+
     if (DL.isNonIntegralAddressSpace(FromAS))
       return std::pair(KnownBits(DL.getPointerSizeInBits(FromAS)),
                        KnownBits(DL.getPointerSizeInBits(ToAS)));
 
     KnownBits FromPtrBits;
     if (const AddrSpaceCastInst *CastI = dyn_cast<AddrSpaceCastInst>(&PtrOp)) {
       std::pair<KnownBits, KnownBits> KB = computeKnownBitsAddrSpaceCast(
-          CastI->getSrcAddressSpace(), CastI->getDestAddressSpace(),
-          *CastI->getPointerOperand());
+          CastI->getDestAddressSpace(), *CastI->getPointerOperand());
       FromPtrBits = KB.second;
-    } else if (isa<ConstantPointerNull>(PtrOp) && FromAS == 0) {
+    } else if (const Constant *PtrC = dyn_cast<Constant>(&PtrOp);
----------------
ro-i wrote:

`PatternMatch::match(&PtrOp, PatternMatch::m_Zero())`? that's neat, thanks

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


More information about the llvm-commits mailing list