<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [ppc] slow code for complex boolean expression"
   href="https://llvm.org/bugs/show_bug.cgi?id=27555">27555</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[ppc] slow code for complex boolean expression
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: PowerPC
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>carrot@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>