Hi LLVM developers.
Working with GC pointers (https://llvm.org/docs/LangRef.html#accurate-garbage-collection-intrinsics) there can be a need for some optimizations to get pointer base and/or offset from the base. The base can be calculated by generating needed instructions as it is done by the RewriteStatepointsForGC::findBasePointer() function. The offset can be calculated in the same way. Though to not expose the base calculation and to make the offset calculation as simple as (ptrtoint(derived_ptr) - ptrtoint(base_ptr)), which is illegal outside RewriteStatepointsForGC, 2 intrinsics are proposed:
declare i8 addrspace(1)* @llvm.experimental.gc.get.pointer.base(i8 addrspace(1)* readnone nocapture %base_ptr) nounwind readnone willreturn “gc-leaf-function”
declare i64 @llvm.experimental.gc.get.pointer.offset(i8 addrspace(1)* readnone nocapture %base_ptr) nounwind readnone willreturn “gc-leaf-function”
These intrinsics are inlined by RewriteStatepointsForGC along with generation of statepoint sequences.
For example, with these new intrinsics the GC parseable lowering for atomic memcpy intrinsics (https://reviews.llvm.org/D88861) could be implemented as a separate pass.
Here is a patch that implements the proposal.
https://reviews.llvm.org/D100445 [RS4GC] Introduce intrinsics to get base ptr and offset