https://bugs.llvm.org/show_bug.cgi?id=52195

            Bug ID: 52195
           Summary: missed optimization: external pointer used as integer
                    should fold into immediate operand
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

When a program converts an external pointer to an integer, LLVM won't use the
resulting value as an immediate operand.

Example 1: https://godbolt.org/z/hnKoWcvGc

  #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: https://godbolt.org/z/46vEEjbnY

  #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).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to