[llvm-bugs] [Bug 46962] New: Remove impossible branches

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 2 10:11:44 PDT 2020


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

            Bug ID: 46962
           Summary: Remove impossible branches
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Interprocedural Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

unsigned deadbranches(bool A, bool B)

{

 if (A || B) {
     if (A && B) {
       return foo1();
     } 

     else if (A) {
       return foo2();
     } 

     else if (B) {
        return foo3();
     } 

     else {
        return foo5();
     }
    }
    return foo4();
}

else branch: return foo5(); is dead, but Clang does not remove it.

Clang:
deadbranches(bool, bool):                     # @deadbranches(bool, bool)
        test    edi, edi
        jne     .LBB0_2
        test    sil, sil
        jne     .LBB0_2
        jmp     foo4()                        # TAILCALL
.LBB0_2:
        test    dil, dil
        je      .LBB0_4
        test    sil, sil
        je      .LBB0_4
        jmp     foo1()                        # TAILCALL
.LBB0_4:
        test    dil, dil
        je      .LBB0_5
        jmp     foo2()                        # TAILCALL
.LBB0_5:
        test    sil, sil
        je      .LBB0_6
        jmp     foo3()                        # TAILCALL
.LBB0_6:
        jmp     foo5()                        # TAILCALL


GCC:

deadbranches(bool, bool):
        test    dil, dil
        jne     .L7
        test    sil, sil
        je      .L9
.L5:
        jmp     foo3()
.L9:
        jmp     foo4()
.L7:
        test    sil, sil
        je      .L4
        jmp     foo1()
.L4:
        test    dil, dil
        je      .L5
        jmp     foo2()



https://godbolt.org/z/Es5z1x

-- 
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/20200802/ccdd2f5b/attachment-0001.html>


More information about the llvm-bugs mailing list