Skip to content

[x86] Unable to fold table lookup into tail call #136848

@zmodem

Description

@zmodem

Reported by @haberman

Consider:

typedef void Func(void *table, long idx);

void ExtraMov(Func** table, long idx) {
    return table[idx](table, idx);
}

Actual output:

ExtraMov(void (**)(void*, long), long):
        mov     rax, qword ptr [rdi + 8*rsi]
        jmp     rax

Desired output:

ExtraMov(void (**)(void*, long), long):
        jmp     qword ptr [rdi + 8*rsi]

(GCC can do it: https://godbolt.org/z/73rGW9M45)

(For 32-bit x86 we get it right, but only for -fno-pic; for -fpic we get confused: https://godbolt.org/z/1e9s787Gr)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions