[llvm-bugs] [Bug 29095] New: CGP generates inefficient branch for double selects

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Aug 22 11:23:07 PDT 2016


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

            Bug ID: 29095
           Summary: CGP generates inefficient branch for double selects
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: danielcdh at gmail.com
                CC: davidxl at google.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

int*
rbsearch(int c, int *t, int n, int ne)
{
        int *p;
        int m;

        while(n > 1) {
                m = n >> 1;
                p = t + m*ne;
                if(__builtin_expect(c >= p[0], true)) {
                        t = p;
                        n = n-m;
                } else
                        n = m;
        }
        return t;
}

For this test case, building with clang -O2, the generated x86 code is has
something like:

        cmpl    %edi, %r9d
        jle     .LBB0_3
# BB#2:
        movl    %r10d, %edx
        jmp     .LBB0_4
        .p2align        4, 0x90
.LBB0_3:
        subl    %r10d, %edx
.LBB0_4:
        cmpl    %edi, %r9d
        jg      .LBB0_6

Note that the two cmpl instructions are redundant. The problem is gone if the
code is compiled with -mllvm -phi-node-folding-threshold=0

The issue is that CGP generates 2 conditional branches (with same condition)
for 2 select instructions.

-- 
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/20160822/f3c9bc4a/attachment-0001.html>


More information about the llvm-bugs mailing list