[PATCH] D37419: Teach scalar evolution to handle inttoptr/ptrtoint

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 3 14:09:30 PDT 2017


On Sun, Sep 3, 2017 at 12:09 PM, Sanjoy Das via Phabricator <
reviews at reviews.llvm.org> wrote:

> sanjoy requested changes to this revision.
> sanjoy added a comment.
> This revision now requires changes to proceed.
>
> Hi David,
>
> Generally it is not safe to look through `inttoptr` and `ptrtoint` in
> SCEV.  https://github.com/llvm-mirror/llvm/blob/master/lib/
> Analysis/ScalarEvolution.cpp#L6053 has a little bit of the rationale, but
> basically the problem is that in:
>
>
Heh, interestingly, that old comment is right below the changes I made, but
I did not notice it :)




>   %i0 = ptrtoint i8* %p0 to i64
>   %i1 = ptrtoint i8* %p1 to i64
>   %i2 = add i32 %i0, %i1
>   %ptr = inttoptr i64 %i2 to i8*
>
> `%ptr` can alias both `%p0` and `%p1`.  However, if you round-trip `%ptr`
> through SCEV and SCEVExpander, then nothing stops SCEVExpander from
> expanding the SCEV for `%ptr` to
>
>   %i0 = ptrtoint i8* %p0 to i64
>   %i1 = ptrtoint i8* %p1 to i64
>   %p0_ = inttoptr i64 %i0 to i8*
>   %ptr = getelementptr i8, i8* %p0_, i64 %p0
>

 you mean

%ptr = getelementptr i8, i8* %p0_, i64 %p1 ?



> and `%ptr` no longer aliases `%p1` (assume that we can prove `%p0`
> no-alias `%p1` in both the snippets).
>


This looks like a convincing example. Do you consider this a bug in the
SCEV expander to be fixed?


>
> In other words, `ptrtoint` and `inttoptr` are not the same as `bitcast`
> since the former two have aliasing implications while the latter does not.
>
> We could fix this in SCEV with some representational changes, but before
> that I'd prefer exploring Hal's direction of avoiding generating `ptrtoint`
> and `inttoptr` altogether.
>

Yes, I will look into the pass that generates the intptr/ptrint conversion
first and see if it is possible to eliminate it. Will revisit this once we
have more information.

thanks,

David


>
>
> https://reviews.llvm.org/D37419
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170903/ca50070f/attachment.html>


More information about the llvm-commits mailing list