[llvm-bugs] [Bug 50125] New: Missed conditional tail call opportunity

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 26 06:58:43 PDT 2021


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

            Bug ID: 50125
           Summary: Missed conditional tail call opportunity
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Common Code Generator Code
          Assignee: unassignedbugs at nondot.org
          Reporter: hans at chromium.org
                CC: llvm-bugs at lists.llvm.org

Based on an example from
https://blog.reverberate.org/2021/04/21/musttail-efficient-interpreters.html
(https://godbolt.org/z/4afYjjPro)

$ cat /tmp/a.c
void *fallback(unsigned char *data);
void *stuff(unsigned char *data);

void *foo(unsigned char *data)
{
  if (*data & 0x1) {
    return fallback(data);
  }
  data++;
  return stuff(data);
}

$ clang -target x86_64-unknown-linux-gnu -Os -S -o - /tmp/a.c
        .text
        .file   "a.c"
        .globl  foo                             # -- Begin function foo
        .type   foo, at function
foo:                                    # @foo
        .cfi_startproc
# %bb.0:                                # %entry
        testb   $1, (%rdi)
        jne     .LBB0_1
# %bb.2:                                # %if.end
        incq    %rdi
        jmp     stuff                           # TAILCALL
.LBB0_1:                                # %if.then
        jmp     fallback                        # TAILCALL
.Lfunc_end0:
        .size   foo, .Lfunc_end0-foo
        .cfi_endproc



Instead of:

        jne     .LBB0_1
.LBB0_1:
        jmp     fallback

It could just do:

        jne     .LBB0_1


The code in BranchFolding.cpp is supposed to do this:
https://github.com/llvm/llvm-project/blob/e439a463a30833f1c7d366ed722f0f12d1682638/llvm/lib/CodeGen/BranchFolding.cpp#L1520

But it's not firing here.

-- 
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/20210426/95461312/attachment-0001.html>


More information about the llvm-bugs mailing list