[PATCH] D114988: [IR] `GetElementPtrInst`: per-index `inrange` support

Nuno Lopes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 5 07:41:42 PST 2021


nlopes added a comment.

(thinking out loud)
The main issue seems to be that C's memory model allows field-sensitive AA, while LLVM does not. But each field is not an object on its own, it's more like a sub-object. In C, you can memcpy a whole struct, as it's an object, but once you index into a specific filed you can't dereference another field.
It's as if the struct is an object and each field is a sub-object.

Re inrange, currently it doesn't disallow OOB pointers; it just says that dereferencing such pointers triggers UB. Eli's example is actually fine with the current wording. It's just that the current wording is not consistent with the rest of LangRef; it requires additional machinery in the memory model.
Other 2 possibilities that come to mind are TBAA and the proposal to handle C's restrict that pushes provenance information to memory operations rather than having it in GEPs. Though it's unclear to me whether tagging memory operations is even possible.

In the past, Johannes proposed using range information for the variables in GEP (using the assumptions machinery already available). That could work, but we need to make sure it doesn't block optimizations. We don't LLVM to trigger UB if an array index is OOB; we just need it to turn poison. The current ranges trigger UB AFAIR.

IMHO, we need a group of people to commit to studying the different features that are needed and make a consistent design to avoid the current patchwork we have. Not an easy feat, though.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114988/new/

https://reviews.llvm.org/D114988



More information about the llvm-commits mailing list