<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - missed optimization: external pointer used as integer should fold into immediate operand"
   href="https://bugs.llvm.org/show_bug.cgi?id=52195">52195</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>missed optimization: external pointer used as integer should fold into immediate operand
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jhaberman@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>When a program converts an external pointer to an integer, LLVM won't use the
resulting value as an immediate operand.

Example 1: <a href="https://godbolt.org/z/hnKoWcvGc">https://godbolt.org/z/hnKoWcvGc</a>

  #include <stdint.h>

  extern char addr;
  void g(unsigned);

  void f(unsigned x) {
    unsigned val = (unsigned)(uintptr_t)&addr;
    return g(x + val);
  }

Output:

  f:                                      # @f
        mov     eax, offset addr
        add     edi, eax
        jmp     g                               # TAILCALL

Desired output:

  f:                                      # @f
        add     edi, offset addr
        jmp     g                               # TAILCALL

Example 2: <a href="https://godbolt.org/z/46vEEjbnY">https://godbolt.org/z/46vEEjbnY</a>

  #include <stdint.h>

  extern char addr;
  void g(unsigned long);

  void f(unsigned long x) {
    unsigned long val = (unsigned)(uintptr_t)&addr;
    return g(x + val);
  }

Output:

  f:                                      # @f
        mov     eax, offset addr
        mov     eax, eax
        add     rdi, rax
        jmp     g                               # TAILCALL  

Desired output:

  f:                                      # @f
        add     rdi, offset addr
        jmp     g   

These examples may seem unusual, but I am considering a novel JIT design where
I would use the compiler's relocatable output as JIT input, and use the emitted
relocations to tell me where to "patch in" my runtime values (which will be
integers, not actually pointers).</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>