<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Opportunity to remove null pointer checks (IPO)"
   href="https://bugs.llvm.org/show_bug.cgi?id=46949">46949</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Opportunity to remove null pointer checks  (IPO)
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Interprocedural Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>david.bolvansky@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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").


<a href="https://godbolt.org/z/or9oW5">https://godbolt.org/z/or9oW5</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>