[llvm] [InferAddressSpaces] Handle unconverted ptrmask (PR #140802)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 2 05:48:14 PDT 2025
================
@@ -151,6 +152,34 @@ class TargetTransformInfoImplBase {
}
virtual bool isNoopAddrSpaceCast(unsigned, unsigned) const { return false; }
+
+ // Assuming that the cast between the two given addrspaces is not a noop,
+ // calculate the width of the given mask value so that it can be applied to
+ // the destination addrspace. In case it cannot be applied since the cast
+ // between the two addrspaces is invalid or the mask value is larger than the
+ // resulting addrspace bit-width, return an empty optional.
+ //
+ // Note that this currently expects the addrspaces to be integral. In case one
+ // of them isn't, an empty optional is returned.
+ virtual std::optional<uint64_t>
+ getAddrSpaceCastMaskWidth(unsigned FromAS, unsigned ToAS, Value *MaskOp,
+ Instruction *I) const {
+ if (DL.isNonIntegralAddressSpace(FromAS) ||
+ DL.isNonIntegralAddressSpace(ToAS))
+ return std::nullopt;
+ // All valid 64-bit to 32-bit casts work by chopping off the high
+ // bits. Any masking only clearing the low bits will also apply in the new
+ // address space.
+ if (DL.getPointerSizeInBits(FromAS) != 64 ||
+ DL.getPointerSizeInBits(ToAS) != 32)
+ return std::nullopt;
+ // TODO: Do we need to thread more context in here?
+ KnownBits Known = computeKnownBits(MaskOp, DL, nullptr, I);
+ if (Known.countMinLeadingOnes() < 32)
+ return std::nullopt;
+ return 32;
----------------
arsenm wrote:
Generalize in terms of the queried address space sizes instead of bailing on this one combination
https://github.com/llvm/llvm-project/pull/140802
More information about the llvm-commits
mailing list