<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hi,</p>
    <p>The semantics of addrspacecast
      (<a class="moz-txt-link-freetext" href="https://llvm.org/docs/LangRef.html#addrspacecast-to-instruction">https://llvm.org/docs/LangRef.html#addrspacecast-to-instruction</a>)
      are:</p>
    <blockquote>
      <p>The ‘<code class="docutils literal notranslate"><span
            class="pre">addrspacecast</span></code>’ instruction
        converts the pointer value
        <code class="docutils literal notranslate"><span class="pre">ptrval</span></code>
        to type <code class="docutils literal notranslate"><span
            class="pre">pty2</span></code>. <u>It can be a </u><u><em>no-op
            cast</em></u><u> or a complex
          value modification, depending on the target and the address
          space
          pair.</u> Pointer conversions within the same address space
        must be
        performed with the <code class="docutils literal notranslate"><span
            class="pre">bitcast</span></code> instruction. Note that if
        the address space
        conversion is legal then both result and operand refer to the
        same memory
        location.</p>
    </blockquote>
    <p>So whether it is valid for instcombine to optimise your example
      depends on the target. It would be wrong for instcombine to
      unconditionally optimise this to i64 3098316506530080114. It might
      be possible to extend it to optimise this when the optimisation is
      valid by getting extra information from the target, there is a
      isNoopAddrSpaceCast function already that can be used to determine
      whether it is valid, but the function you are looking at is
      target-independent, it cannot get target info. It will require
      some thought on the design.<br>
    </p>
    <div class="moz-cite-prefix">On 30/07/2021 08:19, Kavindu Gimhan
      Zoysa via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CALoJghWq+sHBr9QizYZdhLVW=twU18QfEkhVnDrFNnVHegJCXA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hi all,
        <div><br>
        </div>
        <div><b>ptrtoint (i8* addrspacecast (i8 addrspace(1)* inttoptr
            (i64 3098316506530080114 to i8 addrspace(1)*) to i8*) to
            i64)</b><br>
        </div>
        <div><br>
        </div>
        <div>As shown <a
href="https://github.com/llvm/llvm-project/blob/main/llvm/lib/IR/Instructions.cpp#L2797"
            target="_blank" moz-do-not-send="true">here</a>, ptrtoint
          -> addrspacecast is disallowed in <b>instcombine</b> pass.
          Can you please explain to me the reason behind this?</div>
        <div><br>
        </div>
        <div>If I run the <b>instcombine</b> pass against the above
          instructions, nothing happens. But if I remove it, the code
          got optimized.</div>
        <div><br>
        </div>
        <div>Thank you,</div>
        <div>Kavindu</div>
        <div><br clear="all">
          <div>
            <div dir="ltr" data-smartmail="gmail_signature">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div>Kavindu Gimhan Zoysa,</div>
                      <div>BSc(Hons) | ENTC | UoM,<br>
                      </div>
                      <div dir="ltr">ATL | WSO2
                        <div><br>
                        </div>
                        <div><a href="https://github.com/KavinduZoysa"
                            target="_blank" moz-do-not-send="true">GitHub</a> <a
href="https://www.linkedin.com/in/kavindu-gimhan-zoysa-85939a122/"
                            target="_blank" moz-do-not-send="true">LinkedIn</a> <a
href="https://medium.com/@kavindugimhanzoysa" target="_blank"
                            moz-do-not-send="true">Medium</a></div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
  </body>
</html>