llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.75k stars 11.89k forks source link

clang 18 fails tail call #114121

Open hjl-tools opened 5 hours ago

hjl-tools commented 5 hours ago

[hjl@gnu-tgl-3 pr14907]$ cat s.c
extern int baz (long c1);

int
foo (short c1)
{
  return baz (c1);
}
[hjl@gnu-tgl-3 pr14907]$ clang -S -O2 s.c
[hjl@gnu-tgl-3 pr14907]$ cat s.s
    .text
    .file   "s.c"
    .globl  foo                             # -- Begin function foo
    .p2align    4, 0x90
    .type   foo,@function
foo:                                    # @foo
    .cfi_startproc
# %bb.0:
    movslq  %edi, %rdi
    jmp baz                             # TAILCALL
.Lfunc_end0:
    .size   foo, .Lfunc_end0-foo
    .cfi_endproc
                                        # -- End function
    .ident  "clang version 18.1.8 (Fedora 18.1.8-1.fc40)"
    .section    ".note.GNU-stack","",@progbits
    .addrsig
[hjl@gnu-tgl-3 pr14907]$ 
``

"movslq %edi, %rdi" should be "movswq   %di, %rdi"
efriedma-quic commented 2 hours ago

LLVM assumes %edi contain a sign-extended value on entry to the function. So the suggested code is equivalent to what LLVM currently generates, I think?