<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 - Missed DCE/loop deletion"
   href="https://bugs.llvm.org/show_bug.cgi?id=52355">52355</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed DCE/loop deletion
          </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>Loop Optimizer
          </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>inline unsigned int
stringLen(const short* const src)
{
    if (src == 0 || *src == 0) {
        return 0;
    } else {
        const short* pszTmp = src + 1;

        while (*pszTmp)
            ++pszTmp;

        return (unsigned int)(pszTmp - src);
    }
}

extern void bar();

void foo(const short* const str) {
    unsigned int len = stringLen(str);
    if (!len) {
        bar();
    }
}

LLVM:
foo(short const*):                              # @foo(short const*)
        test    rdi, rdi
        je      .LBB0_6
        cmp     word ptr [rdi], 0
        je      .LBB0_6
        xor     eax, eax
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
        cmp     word ptr [rdi + rax + 2], 0
        lea     rax, [rax + 2]
        jne     .LBB0_3
        shr     rax
        test    eax, eax
        je      .LBB0_6
        ret
.LBB0_6:
        jmp     bar()                         # TAILCALL

ICC is smarter here:
foo(short const*):
        test      rdi, rdi                                      #4.16
        je        ..B1.4        # Prob 5%                       #4.16
        movsx     eax, WORD PTR [rdi]                           #4.22
        test      eax, eax                                      #4.29
        jne       ..B1.5        # Prob 72%                      #4.29
..B1.4:                         # Preds ..B1.2 ..B1.1
        jmp       bar()                                       #21.9
..B1.5:                         # Preds ..B1.2
        ret


<a href="https://godbolt.org/z/erWa6efKa">https://godbolt.org/z/erWa6efKa</a>                                                
    #23.1</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>