[llvm-bugs] [Bug 43023] New: Suboptimal code generation for binary-operator parameter pack expansion.

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 16 14:03:02 PDT 2019


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

            Bug ID: 43023
           Summary: Suboptimal code generation for binary-operator
                    parameter pack expansion.
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: mike.k at digitalcarbide.com
                CC: llvm-bugs at lists.llvm.org

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.

-- 
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/20190816/936195b8/attachment.html>


More information about the llvm-bugs mailing list