Issue 55486
Summary x86: missing jmp [rax] optimization on non-niladic virtual functions
Labels new issue
Assignees
Reporter Alcaro
    ```c++
struct x0 {
    virtual void y();
};
void a(x0* b) {
    b->y();
}

struct x1 {
    virtual void y(int);
};
void a(x1* b) {
    b->y(0);
}
void a(x1* b, int t) {
    b->y(t);
}
```
with -O2 or -Os. Result:
```asm
a(x0*):                               # @a(x0*)
        mov     rax, qword ptr [rdi]
        jmp     qword ptr [rax]                 # TAILCALL
a(x1*):                               # @a(x1*)
        mov     rax, qword ptr [rdi]
        mov     rax, qword ptr [rax]
        xor     esi, esi
        jmp     rax                             # TAILCALL
a(x1*, int):                              # @a(x1*, int)
        mov     rax, qword ptr [rdi]
        mov     rax, qword ptr [rax]
        jmp     rax                             # TAILCALL
```
The first function is fully optimized, but the latter two are not. I'd rather see
```asm
a(x0*):                               # @a(x0*)
        mov     rax, qword ptr [rdi]
        jmp     qword ptr [rax]                 # TAILCALL
a(x1*):                               # @a(x1*)
        mov     rax, qword ptr [rdi]
        xor     esi, esi
        jmp     qword ptr [rax]                 # TAILCALL
a(x1*, int):                              # @a(x1*, int)
        mov     rax, qword ptr [rdi]
        jmp     qword ptr [rax]                 # TAILCALL
```
GCC fully optimizes the third function, but not the second. https://godbolt.org/z/5xoxdb6YK
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to