[llvm] [IR] Require that ptrmask mask matches pointer index size (PR #69343)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 18 11:51:01 PDT 2023


================
@@ -26965,10 +26966,20 @@ 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
+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
----------------
jayfoad wrote:

I was thinking of an example like this, with 16-bit pointers and 8-bit indexes:
```
  %ptr = ptr 0x6789
  %mask = i8 0x00
  // ptrmask(%ptr, %mask) expands to:
  %intptr = i8 0x89
  %masked = i8 0x00
  %diff = i8 0x77
  %result = getelementptr i8, ptr 0x6789, i8 0x77
          = ptr 0x6800 // not 0x6700!
```
Have I misunderstood how getelementptr works?

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


More information about the llvm-commits mailing list