<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 25, 2016 at 1:48 PM, Rafael Espíndola via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">So, for the declaration, do you expect to know the value? If not just<br>
a declaration to a GlobalVariable should be sufficient.<br></blockquote><div><br></div><div>No, the value will be discovered at link time, but we want instruction selection to treat the symbol as an immediate, not a GlobalAddress that will receive PIC and GOT treatment.</div><div><br></div><div>If we use a declaration as you suggest, this example will compile awkwardly:</div><div><br></div><div>@foo = external global i8</div><div>define i64 @addfoo(i64 %v) {</div><div>  %cast = ptrtoint i8* @foo to i64</div><div>  %v1 = add i64 %v, %cast</div><div>  ret i64 %v1<br>}</div><div><br></div><div>The ideal code is:</div><div>addfoo:</div><div>  leaq foo(%rdi), %rax</div><div>  retq</div><div><br></div><div>Today we select:</div><div>addfoo:</div><div><div>        addq    foo@GOTPCREL(%rip), %rdi</div><div>        movq    %rdi, %rax</div><div>        retq</div></div><div><br></div><div>We could use attributes to try to convince ISel not to form GlobalAddress nodes, but we might also want to consider just adding a new kind of global.</div><div><br></div><div>Chris's proposal of giving this new globalconst pointer type seems like a reasonable compromise to avoid disturbing the rest of LLVM. The ptrtoint cast will go away when we build MI.</div></div></div></div>