[LLVMbugs] [Bug 21929] New: Missed optimisation for modulo 2

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Dec 16 10:29:42 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21929

            Bug ID: 21929
           Summary: Missed optimisation for modulo 2
           Product: new-bugs
           Version: 3.4
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: nick at indigorenderer.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

See Godbolt snippet here: http://goo.gl/imHtck



inline int intMod(int x, int y)
{
    const int r = x % y;
    if(r < 0)
        return y + r;
    else
        return r;
}

int f(int x)
{
  return intMod(x, 2); // Should this optimse to x & 0x1 ?
  //return x & 0x1;
}


Compiles to:

f(int):                                  # @f(int)
    movl    %edi, %eax
    shrl    $31, %eax
    addl    %edi, %eax
    andl    $-2, %eax
    subl    %eax, %edi
    movl    %edi, %eax
    shrl    $31, %eax
    leal    (%rdi,%rax,2), %eax
    ret


It seems to be valid to make the optimisation intMod(x, 2) = x & 0x1,
which LLVM doesn't do.

-- 
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/20141216/ce344c0c/attachment.html>


More information about the llvm-bugs mailing list