[llvm] [LangRef] Specify icmp on pointers to only compare address (PR #163936)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 02:47:40 PDT 2025
nikic wrote:
@davidchisnall I've now included in this PR the necessary adjustments to the pointer equality replacement fold, to clarify what the impact on "pointer substitutability" with this change is. The only impact is that for pointers where we cannot guarantee the same underlying object, and where the pointer has non-address bits, we can now no longer replace uses inside ptrtoint (but can still replace uses in ptrtoaddr). As CHERI shouldn't be using ptrtoint anyway, that should have no practical impact. And on top of that, the ptrtoint replacement is incorrect anyway and will likely be dropped once we start using ptrtoaddr in key places.
> This is currently the behaviour of CHERI C/C++. As we've had more people trying to write these dialects, we've found that this is the number one source of friction. In CHERIoT, our C++ wrapper type around a CHERI capability uses exact (all bits including tag) and we have found from user feedback that this is a more understandable behaviour.
I've been thinking about this some more, and I think the best way to handle these semantics would be to use an intrinsic for equality comparisons that include the non-address bits and tag, and then try to fold it to an address-only icmp in cases where you can guarantee that the non-address bits / tag are the same. The address-only icmp would then optimize as usual. I don't think there is anything useful in terms of generic optimizations that LLVM could do for an icmp that includes not just the non-address bits but also the hidden state.
https://github.com/llvm/llvm-project/pull/163936
More information about the llvm-commits
mailing list