[llvm] [InferAddressSpaces] Handle unconverted ptrmask (PR #140802)
    Matt Arsenault via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Sep 24 20:46:36 PDT 2025
    
    
  
================
@@ -151,6 +152,54 @@ 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 {
+    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());
+      FromPtrBits = KB.second;
+    } else if (isa<ConstantPointerNull>(PtrOp) && FromAS == 0) {
----------------
arsenm wrote:
```suggestion
    } else if (FromAS == 0 && PtrOp->isNullValue()) {
```
This will handle the vector case too 
https://github.com/llvm/llvm-project/pull/140802
    
    
More information about the llvm-commits
mailing list