[PATCH] D107822: [InstCombine] Fold Int2Ptr/PtrToInt if the ptr is dereferenceable

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 19 00:11:21 PDT 2021


aqjune added a comment.

Hi,

I became to wonder what happens if a pointer is freed in the function.
For example:

  // assume that %p is dereferenceable(8)
  call void @g(%p);
  %q = inttoptr (ptrtoint %p);
  use(%q); // can we replace this with %p?

I guess the answer is no, because if `@g` freed %p and allocated an object at `%p`'s location, replacing `inttoptr(ptrtoint %p)` with `%p` makes the program more undefined.

Is the semantics of `dereferenceable(8) %p` implying `%p` must not be freed in the function as well?
If it isn't I think we should check whether `nofree` flag is attached to the functions (`@test`, `@test1`, ...) as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107822



More information about the llvm-commits mailing list