<div dir="ltr">Hi,<br><br>Although I'm not an expert on the topic, there are at least two reasons:<br>1) It looks more like C/C++ than computing offsets. This goes hand in hand with the fact that GEP abstracts<br>target-specific information. For example, a pointer is 4 bytes in a typical 32-bit system but 8 bytes in a 64-bit system.<br>If you have a struct like:<br>struct {<br> int *p;<br> int v;<br>};<br><br>To get `v`, with a GEP you just say "give me the second member". If you were to code this with offsets, you would need to<div>know the target, something that generally front-ends are not good to have a dependency on (Clang and other front-ends actually<br>have and that's another big discussion).<br><br>2) It's very important for alias analysis. Again, not an expert on that, but e.g. see the first rule on when a pointer is based on<br>another (pointer) here: <a href="https://llvm.org/docs/LangRef.html#pointeraliasing">https://llvm.org/docs/LangRef.html#pointeraliasing</a><br><br>Best regards,<br>Stefanos</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Στις Δευ, 13 Ιουλ 2020 στις 11:08 μ.μ., ο/η Nikita Popov via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> έγραψε:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hi,</div><div><br></div><div>I've been wondering why LLVMs GEP instructions are based on types, rather than encoding the raw address calculation as a base pointer plus some scaled offsets (still in the form of a GEP, to retain provenance).</div><div><br></div><div>The type information does not seem particularly useful (shouldn't be used as an optimization base, because struct layouts lie), but increases the non-canonical IR space (there are many ways to encode the same GEP) and increases compile-time (optimizations need to constantly decompose GEPs, e.g. to get constant offsets).</div><div><br></div><div>What am I missing here?<br></div><div><br></div><div>Nikita,</div><div>Regards<br></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>