<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - Suboptimal code generation for binary-operator parameter pack expansion."
   href="https://bugs.llvm.org/show_bug.cgi?id=43023">43023</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Suboptimal code generation for binary-operator parameter pack expansion.
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mike.k@digitalcarbide.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Given the following C++2a code:

bool ref (int a) {
    return (a == -1) | (a == 0) | (a == 3) | (a == 4) | (a == 5);
}

bool test (int a) {
    return [a](auto... args) {
        return ((a == args) | ...);
    }(-1, 0, 3, 4, 5);
}

The following LLVM IR is produced with -O3:

define dso_local zeroext i1 @_Z3refi(i32 %0) local_unnamed_addr #0 {
  %2 = add i32 %0, 1
  %3 = icmp ult i32 %2, 2
  %4 = add i32 %0, -3
  %5 = icmp ult i32 %4, 3
  %6 = or i1 %5, %3
  ret i1 %6
}

define dso_local zeroext i1 @_Z4testi(i32 %0) local_unnamed_addr #1 {
  %2 = icmp eq i32 %0, 3
  %3 = or i32 %0, 1
  %4 = icmp eq i32 %3, 5
  %5 = or i1 %2, %4
  %6 = add i32 %0, 1
  %7 = icmp ult i32 %6, 2
  %8 = or i1 %7, %5
  ret i1 %8
}

Resulting in the following x86-64 assembly:

ref(int): # @ref(int)
  lea eax, [rdi + 1]
  cmp eax, 2
  setb cl
  add edi, -3
  cmp edi, 3
  setb al
  or al, cl
  ret
test(int): # @test(int)
  cmp edi, 3
  sete al
  mov ecx, edi
  or ecx, 1
  cmp ecx, 5
  sete cl
  or cl, al
  add edi, 1
  cmp edi, 2
  setb al
  or al, cl
  ret

It appears as though a different pattern is being generated when expanding the
parameter pack along with the binary-or operator, and is not being optimized in
the same fashion.</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>