[PATCH] D104322: [SCEV] PtrToInt on non-integral pointers is allowed

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 16 08:57:02 PDT 2021


reames added a comment.

In D104322#2822104 <https://reviews.llvm.org/D104322#2822104>, @lebedev.ri wrote:

> In D104322#2822083 <https://reviews.llvm.org/D104322#2822083>, @nikic wrote:
>
>> As a drive-by note, it would be great if you could expand LangRef on non-integral pointers a bit. It made sense to me when it specified that you can't use `ptrtoint` on a non-integral pointer, but without that limitation, it's not really clear to me what the actual difference between a non-integral pointer and a normal one is. What transforms are you not allowed to perform on a non-integral pointer that you can perform on a normal one?
>
> Yes, i would also like to see such documentation, especially if non-integral pointers
> are going to be used as an "arbitrary" roadblock for SCEV changes. I would have posted
> that in the review for the commit mentioned, but there was none, which also highlights
> the problem around non-integral pointer status in llvm :)

On the documentation side, I'd love to, but I'm honestly not sure *how* to.  There's two inter-related problems here.  The first is the semantics of an inttoptr is highly dependent on the target for non-integral pointers.  At the moment, it can basically only be used to implement non-inlined built-in routines in any practical way.  The second issue is that our definition of the integral pointer types themselves appear to be in flux, and are very vague about certain key details.  The result is I'm left unsure how to formally specify them.  This is why I used the implementation defined wording I did.

On the SCEV side, I understand the frustration, but I think you're also mischaracterizing slightly.  SCEV has long had the notion of subtracting two pointers which has been "questionable" the whole time as the semantics of subtracting two unrelated pointers is unclear from the underlying IE.  (IR doesn't have subtract, but it does have icmp which is more or less the same.)  Eli's recent changes - which are making progress btw, even if slow - are the first I've seen to really raise the question if subtract is a primitive which should be representable for pointers in SCEV.  (I'll also add that the confusion around whether we could still have sizeless pointers - which I admittedly contributed to - has only recently been cleared up.)

In terms of forward progress, I am willing to accept crippling SCEV for NI pointers provided that all the changes are otherwise well structured and make sense.  I'm not thrilled, and I will be a skeptical reviewer, but I won't block changes which are well justified.

Hm, random vaguely OT thought, would it be worthwhile to add an explicit pointer difference node in SCEV?  This would allow us to form subtracts of pointers without needing the nasty multiply by negative one trick, and we could optimize them to the lossless inttoptr form for integral pointers, and not for NI pointers.  Might be worth a bit of further thought.  I'll follow up if I still think this is a good idea in an hour.  :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104322



More information about the llvm-commits mailing list