[LLVMbugs] [Bug 16010] New: Fail to generate indirect jmp with memory operand (for tail call)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue May 14 22:25:34 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16010

            Bug ID: 16010
           Summary: Fail to generate indirect jmp with memory operand (for
                    tail call)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: silvas at purdue.edu
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

We could fold a load + indirect jump through reg into just an indirect jump
through memory.

typedef void fn(int reg, int *pc);
fn *dispatch_tab[0xFF];
void test_no_mem_indirect_jmp_tail(int reg, int *pc) {
  (*dispatch_tab[pc[0] & 0xFF])(reg, pc);
}

0000000000000000 <test_no_mem_indirect_jmp_tail>:
   0:   8b 06                   mov    eax,DWORD PTR [rsi]
   2:   0f b6 c0                movzx  eax,al
   5:   48 8b 04 c5 00 00 00 00 mov    rax,QWORD PTR [rax*8+0x0]
   d:   ff e0                   jmp    rax


We could replace:
   5:   48 8b 04 c5 00 00 00 00 mov    rax,QWORD PTR [rax*8+0x0]
   d:   ff e0                   jmp    rax

With:
        ff 24 c5 00 00 00 00    jmp    QWORD PTR [rax*8+0x0]

Interestingly enough, GCC (4.7.3) fails to form the indirect-through-memory jmp
as well.


Also, we form an indirect-through-memory call in the same situation when there
is no tail call (GCC does too):

extern void use(int*);
typedef void fn(int reg, int *pc);
fn *dispatch_tab[0xFF];
void test_no_mem_indirect_jmp_notail(int reg, int *pc) {
  (*dispatch_tab[pc[0] & 0xFF])(reg, pc);
  use(pc);
}


0000000000000000 <test_no_mem_indirect_jmp_notail>:
   0:   53                      push   rbx
   1:   48 89 f3                mov    rbx,rsi
   4:   8b 03                   mov    eax,DWORD PTR [rbx]
   6:   0f b6 c0                movzx  eax,al
   9:   ff 14 c5 00 00 00 00    call   QWORD PTR [rax*8+0x0]       <----
  10:   48 89 df                mov    rdi,rbx
  13:   5b                      pop    rbx
  14:   e9 00 00 00 00          jmp    19
<test_no_mem_indirect_jmp_notail+0x19>

Tested with clang built from trunk on Apr 20, 2013. (this is all with -O2
and -O3)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130515/31ea8f7b/attachment.html>


More information about the llvm-bugs mailing list