[llvm] [Analysis] Use TTI to guard dereferenceability through addrspacecast (PR #198251)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 1 03:46:57 PDT 2026


================
@@ -198,12 +199,18 @@ static bool isDereferenceableAndAlignedPointer(
   if (const GCRelocateInst *RelocateInst = dyn_cast<GCRelocateInst>(V))
     return isDereferenceableAndAlignedPointer(RelocateInst->getDerivedPtr(),
                                               Alignment, Size, DL, CtxI, AC, DT,
-                                              TLI, Visited, MaxDepth);
-
-  if (const AddrSpaceCastOperator *ASC = dyn_cast<AddrSpaceCastOperator>(V))
-    return isDereferenceableAndAlignedPointer(ASC->getOperand(0), Alignment,
-                                              Size, DL, CtxI, AC, DT, TLI,
-                                              Visited, MaxDepth);
+                                              TLI, TTI, Visited, MaxDepth);
+
+  if (const AddrSpaceCastOperator *ASC = dyn_cast<AddrSpaceCastOperator>(V)) {
+    unsigned SrcAS = ASC->getSrcAddressSpace();
+    unsigned DstAS = ASC->getDestAddressSpace();
+    // When TTI is available look through if the cast is a no-op.
+    if (SrcAS == DstAS || !TTI || TTI->isNoopAddrSpaceCast(SrcAS, DstAS))
----------------
nikic wrote:

The way this is implemented means that with `!TTI` we get incorrect behavior. If TTI is not present we should be conservatively assuming that addrspace is never dereferenceable.

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


More information about the llvm-commits mailing list