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

            Bug ID: 41272
           Summary: Failure to hoist constant mask out of loop
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

https://godbolt.org/z/YXhpEv

#include <stdint.h>

uint64_t sum_mask32(const uint64_t *p, int len) {
    uint64_t sum = 0;
    for(int i = 0; i < len; i++) {
        sum += *p++ & 0x80008000;
    }
    return sum;
}

With clang -Os the loop kernel is:

.LBB0_4: # =>This Inner Loop Header: Depth=1
  movq (%rdi,%rdx,8), %rsi
  andl $-2147450880, %esi # imm = 0x80008000
  addq %rsi, %rax
  incq %rdx
  cmpl %edx, %ecx
  jne .LBB0_4
  retq

With clang -O3 the unrolled kernel is even worse:

.LBB0_9: # =>This Inner Loop Header: Depth=1
  movq (%rdi), %rcx
  movq 8(%rdi), %rdx
  andl $-2147450880, %ecx # imm = 0x80008000
  addq %rax, %rcx
  andl $-2147450880, %edx # imm = 0x80008000
  addq %rcx, %rdx
  movq 16(%rdi), %rcx
  andl $-2147450880, %ecx # imm = 0x80008000
  addq %rdx, %rcx
  movq 24(%rdi), %rax
  addq $32, %rdi
  andl $-2147450880, %eax # imm = 0x80008000
  addq %rcx, %rax
  addl $4, %r9d
  jne .LBB0_9
  testl %r8d, %r8d
  je .LBB0_7

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to