<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 pattern 0 modulo/div/mul N in phi"
   href="https://bugs.llvm.org/show_bug.cgi?id=38479">38479</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed pattern 0 modulo/div/mul N in phi
          </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>Scalar 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>unsigned int hash_function(const char *str, unsigned hash_tab_size) {
        unsigned int h = 0;
        const unsigned char *p;
        for (p = (const unsigned char *) str; *p != '\0'; p++)
                h = 65599 * h + *p;
        return h % hash_tab_size;
        // return h / hash_tab_size;
        // return h * hash_tab_size;
        // similar code generation
}

Lets say p[0] is \0   -> .LBB0_1

Latest trunk, O3:
hash_function(char const*, unsigned int):                  #
@hash_function(char const*, unsigned int)
        mov     cl, byte ptr [rdi]
        test    cl, cl
        je      .LBB0_1
        add     rdi, 1
        xor     eax, eax
.LBB0_3:                                # =>This Inner Loop Header: Depth=1
        movzx   ecx, cl
        imul    eax, eax, 65599
        add     eax, ecx
        movzx   ecx, byte ptr [rdi]
        add     rdi, 1
        test    cl, cl
        jne     .LBB0_3
        xor     edx, edx
        div     esi
        mov     eax, edx
        ret
.LBB0_1: 
        xor     eax, eax
        xor     edx, edx     
        div     esi          // useless
        mov     

I believe these are important lines in the IR:
%16 = phi i32 [ 0, %2 ], [ %11, %5 ]
%17 = urem i32 %16, %1
ret i32 %17

In this case we should expand/simplify phi and remove "0 urem %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>