[llvm-bugs] [Bug 47337] New: Slower sieve computation than gcc

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 27 16:01:48 PDT 2020


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

            Bug ID: 47337
           Summary: Slower sieve computation than gcc
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

#define Size 819000
static int sieve (int N) {
  int i, k, prime, count, n; char flags[Size];

  for (n = 0; n < N; n++) {
    count = 0;
    for (i = 0; i < Size; i++)
      flags[i] = 1;
    for (i = 0; i < Size; i++)
      if (flags[i]) {
        prime = i + i + 3;
        for (k = i + prime; k < Size; k += prime)
          flags[k] = 0;
        count++;
      }
  }
  return count;
}
int main (void) {
  __builtin_printf ("sieve (100) = %d", sieve (100));
}


gcc -O3:
0m0,392s

gcc -O3 -march=haswell:
0m0,392s

clang -O3:
0m0,404s

clang -O3 -march=haswell:
0m0,393s



So -march=haswell enables loop unrolling which is profitable for this code.

But gcc does not unroll this loop and it is still faster.

Maybe clang's:

        mov     bl, 1       ***
        xor     ecx, ecx     
        mov     edx, 3
        xor     esi, esi
        test    bl, bl      ***
        je      .LBB0_7
.LBB0_3:                                #   in Loop: Header=BB0_1 Depth=1
        lea     rdi, [rcx + 2*rcx]
        add     rdi, 3
        cmp     rdi, 818999


is slower than gcc's:

        add     rcx, 3
        add     rsi, 1
        add     rdx, 2
        cmp     rcx, 2457003
        je      .L12
.L5:
        cmp     BYTE PTR [rsi], 0
        je      .L2
        cmp     rcx, 818999


Godbolt: https://godbolt.org/z/6ExqE6

-- 
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/20200827/5b899d92/attachment-0001.html>


More information about the llvm-bugs mailing list