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

            Bug ID: 27555
           Summary: [ppc] slow code for complex boolean expression
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedb...@nondot.org
          Reporter: car...@google.com
                CC: llvm-bugs@lists.llvm.org
    Classification: Unclassified

Compile following function with options -mvsx -mcpu=power8 -g0 -O2 

int foo(int i)
{
  return
    (i==5548 || i==6374 || i==5595 || i==8625 || i==8621 || i==8622 || i==6373
  || i==6073 || i==5568 || i==5549 || i==8623 || i==8624 || i==5569 || i==5544
  || i==7727 || i==7746 || i==5570 || i==5543 || i==7728 || i==7747 || i==6026
  || i==6027 || i==374  || i==5333 || i==5332 || i==1027 || i==5337 || i==5336
  || i==8781 || i==8783 || i==8782 || i==8784 || i==2347 || i==5339 || i==5338
  || i==3856 || i==5335 || i==5334 || i==5343 || i==5342 || i==4775);
}

LLVM generates following code:

        cmpwi    3, 5548
        cmpwi 1, 3, 6374
        addi 4, 3, -8621
        addi 10, 3, -8623
        ori 11, 3, 1
        ori 5, 3, 2
        cror 20, 2, 6
        cmpwi    3, 5595
        ori 12, 3, 9
        cror 20, 2, 20
        cmpwi    3, 8625
        cror 20, 2, 20
        cmplwi   4, 2
        cror 20, 0, 20
        ...
        cmpwi 0, 3, 4775
        li 3, 1
        crnor 20, 2, 20
        isel 3, 0, 3, 20
        blr

GCC generates following code:

        rldicl 10,3,0,32
        addi 9,10,-5548
        cmplwi 7,9,1
        ble 7,.L19
        cmpwi 7,3,5595
        beq 7,.L19
        ...
        addi 10,10,-5342
        cmplwi 7,10,1
        ble 7,.L19
        xori 3,3,4775
        cntlzw 3,3 
        srwi 3,3,5
        extsw 3,3 
        blr
        .p2align 4,,15
.L19:
        li 3,1 
        blr


There are two problems in llvm generated code:

1. llvm generates 31 cmp instructions, gcc generates 17 cmp instructions.

2. gcc generates conditional branch instructions, it can shortcut the boolean
expression computation, llvm generates conditional register manipulate
instruction cror, it needs to complete all of the boolean expression
computation.

For an internal application, it causes 3x slow down.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to