On my architecture, a certain important base pointer is stored in a physical register. In the IR, code accesses this pointer via an llvm.read_register.i32 intrinsic. I would like to encode the information that this pointer is dereferenceable so that LICM can speculatively hoist loads derived from that base pointer. Specifically, I want llvm::isDereferenceableAndAlignedPointer() to return true on such pointers, which will cause llvm::isSafeToSpeculativelyExecute() to return true when loading from such pointers.
LLVM features Attribute::Dereferenceable for pointer-valued arguments or return values, or !dereferenceable metadata for pointer-typed results of load instructions. The problem is that llvm.read_register.i32/.i64 return integer values, so they cannot accept Attribute::Dereferenceable. I don't think there is any good way to encode this dereferenceability.
I would appreciate any suggestions. Perhaps the spec could be relaxed to allow !dereferenceable metadata on inttoptr instructions...
D. E. Shaw Research