[PATCH] D37832: Eliminate PHI (int typed) which is only used by inttoptr
Nuno Lopes via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 06:24:02 PDT 2017
nlopes added a comment.
Ok, so after another scan through the patch and a discussion with Gil, I must say the transformation is not fully correct.
The main criteria that allows folding load(int2ptr(ptr2int(x))) -> load(x) is that x must be dereferenceable. It might not be because ptr2int(x) might have been replaced with e.g. ptr2int(y+n), a valid, but out-of-bounds pointer.
For example, in intptr2.ll, it removes ptr2int(b), where b is an argument. This is not correct because we don't know whether b is dereferenceable or not. There are two ways to go around this problem: use the dereferenceable(n) parameter tag, or abuse the noinline function tag. If after the last round of inlining and all of IPAs, the pass manager gave indication to optimizations that no further IP stuff will happen, then we can assume whatever the best case about arguments instead of having to assume the worst case since we don't know where it might be inlined.
Also, the value of the integer value on the back-edge is not checked how it's computed. It needs to check that it's dereferenceable as well. A way to do so is to ensure it comes from a GEP of the PHI value, for example.
For the load case (when the value of initial edge of the PHI is a load), I'm still unsure and I'll study that problem further. Anyway, the other cases need a bit of non-trivial work and discussion.
https://reviews.llvm.org/D37832
More information about the llvm-commits
mailing list