[llvm-bugs] [Bug 38479] New: Missed pattern 0 modulo/div/mul N in phi

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 7 23:45:09 PDT 2018


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

            Bug ID: 38479
           Summary: Missed pattern 0 modulo/div/mul N in phi
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

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"

-- 
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/20180808/302b02b8/attachment.html>


More information about the llvm-bugs mailing list