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

            Bug ID: 32618
           Summary: Improve merging of identical branches
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: c...@trust-in-soft.com
                CC: llvm-bugs@lists.llvm.org

Consider the following code:

  va_list ap;
  void *result;

  va_start(ap, ptr_type);

  switch (ptr_type) {
    case 0: result = va_arg(ap, int*); break;
    case 1: result = va_arg(ap, char*); break;
    case 2: result = va_arg(ap, short*); break;
    default: result = va_arg(ap, void*); break;
  }

  va_end(ap);

Clang correctly recognizes that the assembly code for all four branches is
identical, which is the difficult part (the source code for the branches is
different and cannot be merged by the programmer unless
https://bugs.llvm.org/show_bug.cgi?id=32616 is resolved). At the time of
writing, the Compiler Explorer trunk version produces:

        cmpl    $2, %edi
        je      .LBB0_5
        cmpl    $1, %edi
        je      .LBB0_5
        testl   %edi, %edi
.LBB0_5:

(Compiler Explorer link: https://godbolt.org/g/0NvnSX )

This shows that Clang correctly manages to eliminate the conditional branch in
the pattern:

jcc L
L:

Unfortunately, Clang leaves the “testl   %edi, %edi” that preceded the
conditional branch (and is now useless), and this prevents it from eliminating
all the other conditional branches.

It would be nice if all of the assembly snippet posted above could be
eliminated, especially since there are code patterns that must be different at
the source level and identical in assembly, and Clang already recognizes those.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to