[llvm-bugs] [Bug 46949] New: Opportunity to remove null pointer checks (IPO)

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 1 11:44:04 PDT 2020


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

            Bug ID: 46949
           Summary: Opportunity to remove null pointer checks  (IPO)
           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

void clean(void);

__attribute__((noinline))
static void check(void *p)
{
    if (!p)
        clean();
}

void foo(void *p, void *q)
{
    if (p)
        check(p);
    if (q)
        check(q);
}

void bar(void *p, void *q)
{
    check(p);
    check(q);
}



foo(void*, void*):                             # @foo(void*, void*)
        push    rbx
        mov     rbx, rsi
        test    rdi, rdi
        je      .LBB0_2
        call    check(void*)
.LBB0_2:
        test    rbx, rbx
        je      .LBB0_3
        mov     rdi, rbx
        pop     rbx
        jmp     check(void*)                     # TAILCALL
.LBB0_3:
        pop     rbx
        ret
check(void*):                            # @check(void*)
        test    rdi, rdi
        je      .LBB1_2
        ret
.LBB1_2:
        jmp     clean()                       # TAILCALL
bar(void*, void*):                             # @bar(void*, void*)
        push    rbx
        mov     rbx, rsi
        call    check(void*)
        mov     rdi, rbx
        pop     rbx
        jmp     check(void*)                     # TAILCALL



There is a missed opportunity to remove null pointer checks (optimize "foo" to
"bar").


https://godbolt.org/z/or9oW5

-- 
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/20200801/2a42b9b2/attachment.html>


More information about the llvm-bugs mailing list