[llvm-bugs] [Bug 27136] New: Failure to hoist constant out of loop

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 30 11:20:54 PDT 2016


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

            Bug ID: 27136
           Summary: Failure to hoist constant out of loop
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: chisophugis at gmail.com, llvm-bugs at lists.llvm.org,
                    spatel+llvm at rotateright.com
    Classification: Unclassified

Poor code gen identified in Andreas Fredriksson's GDC 2016 Talk 'Taming the
Jaguar: x86 Optimization at Insomniac Games': 

http://schedule.gdconf.com/session/taming-the-jaguar-x86-optimization-at-insomniac-games

search.c:

#include <stdint.h>
#include <stdbool.h>

bool search(uint32_t needle, const uint32_t *haystack, int count) {
  for (int i = 0; i < count; ++i)
    if (needle == haystack[i])
      return true;
  return false;
}

clang -O3 -S -march=btver2 search.c -o -

_search:
    .cfi_startproc
## BB#0:
    pushq    %rbp
Ltmp0:
    .cfi_def_cfa_offset 16
Ltmp1:
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
Ltmp2:
    .cfi_def_cfa_register %rbp
    testl    %edx, %edx
    jle    LBB0_1
## BB#4:
    movslq    %edx, %rcx
    xorl    %edx, %edx
    .p2align    4, 0x90
LBB0_5:
    cmpl    %edi, (%rsi,%rdx,4)
    movb    $1, %al
    je    LBB0_6
## BB#2:
    incq    %rdx
    cmpq    %rcx, %rdx
    jl    LBB0_5
## BB#3:
    xorl    %eax, %eax
    popq    %rbp
    retq
LBB0_1:
    xorl    %eax, %eax
    popq    %rbp
    retq
LBB0_6:
    popq    %rbp
    retq
    .cfi_endproc

As well as failing to pull the "movb $1, %al" out of the loop (and avoid the
partial register move issue), it also fails to merge the 3 epilogs into
something like:

## BB#3:
LBB0_1:
    xorl    %eax, %eax
LBB0_6:
    popq    %rbp
    retq

-- 
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/20160330/b8360143/attachment.html>


More information about the llvm-bugs mailing list