[llvm-bugs] [Bug 47584] New: Suboptimal constant propagation for unrolled loop

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Sep 19 08:32:48 PDT 2020


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

            Bug ID: 47584
           Summary: Suboptimal constant propagation for unrolled loop
           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

int foo(int p)
{
  unsigned i, s = 0;
  for (i = 4; i < 20; i++)
    {
      if (p)
        s += i*2; // works for i*3
        else
        s += i*4;
    }
  return s;
}

Clang produces:
foo(int):                                # @foo(int)
        cmp     edi, 1
        mov     cl, 1
        adc     cl, 0
        mov     eax, 4
        shl     eax, cl
        mov     edx, 5
        shl     edx, cl
        mov     esi, 6
        shl     esi, cl
        add     edx, eax
        add     esi, edx
        mov     eax, 7
        shl     eax, cl
        add     eax, esi
        mov     edx, 8
        shl     edx, cl
        mov     esi, 9
        shl     esi, cl
        mov     edi, 10
        shl     edi, cl
        add     edx, eax
        add     esi, edx
        ....



But it should just produce:
foo(int):                                # @foo(int)
        test    edi, edi
        mov     ecx, 736
        mov     eax, 368
        cmove   eax, ecx
        ret

-- 
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/20200919/0f69fc8a/attachment.html>


More information about the llvm-bugs mailing list