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

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 27 09:48:51 PDT 2025


================
@@ -151,6 +152,52 @@ class TargetTransformInfoImplBase {
   }
 
   virtual bool isNoopAddrSpaceCast(unsigned, unsigned) const { return false; }
+
+  virtual std::pair<KnownBits, KnownBits>
+  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->getDestAddressSpace(), *CastI->getPointerOperand());
+      FromPtrBits = KB.second;
+    } else if (FromAS == 0 &&
----------------
arichardson wrote:

It would be great if we could avoid adding new checks for AS==0. I think this can easily be handled even without waiting for https://github.com/llvm/llvm-project/pull/131557, by adding something like a `isNullPointerAllZeroes(unsigned AS)` function to DataLayout.h. That function can then do the `AS==0` check and will make it much easier to extend this to other address spaces in the future.

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


More information about the llvm-commits mailing list