[llvm] [IR] Require that ptrmask mask matches pointer index size (PR #69343)
Alexander Richardson via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 11:35:40 PDT 2023
================
@@ -26965,13 +26966,23 @@ to facilitate alias analysis and underlying-object detection.
Semantics:
""""""""""
-The result of ``ptrmask(ptr, mask)`` is equivalent to
-``getelementptr ptr, (ptrtoint(ptr) & mask) - ptrtoint(ptr)``. Both the returned
-pointer(s) and the first argument are based on the same underlying object (for more
-information on the *based on* terminology see
-:ref:`the pointer aliasing rules <pointeraliasing>`). If the bitwidth of the
-mask argument does not match the pointer size of the target, the mask is
-zero-extended or truncated accordingly.
+The result of ``ptrmask(%ptr, %mask)`` is equivalent to the following expansion,
+where ``iPtrIdx`` is the index type size of the pointer::
+
+ %intptr = ptrtoint ptr %ptr to iPtrIdx ; this may truncate
+ %masked = and iPtrIdx %intptr, %mask
+ %diff = sub iPtrIdx %masked, %intptr
+ %result = getelementptr i8, ptr %ptr, iPtrIdx %diff
+
+Considering this as an operation on the integer representation of the pointer,
+if the pointer index type size is smaller than the pointer type size, this
+implies that the mask is extended with 1 bits to the pointer type size.
----------------
arichardson wrote:
```suggestion
if the pointer index type size is smaller than the pointer type size, this
implies pointer bits beyond the index size are not affected by this intrinsic
(as if the mask was extended with 1 bits to the pointer type size for integral pointers).
```
Maybe something like this addresses @jrtc27's comment that non-index bits are not touched at all for CHERI?
https://github.com/llvm/llvm-project/pull/69343
More information about the llvm-commits
mailing list