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

            Bug ID: 34554
           Summary: Code generation regression with trunk
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: m...@godbolt.org
                CC: llvm-bugs@lists.llvm.org

Hi all,

I'm not sure how best to explain what's going on, but this code:

#include <array>
#include <algorithm>

constexpr auto get_array() {
  return std::array<char, 42>{"This is my string that might have a char."};
}

bool has_char(const char c) {
  static constexpr auto a = get_array();
  return std::find(std::begin(a), std::end(a), c) != std::end(a);
}

( https://godbolt.org/g/qW58Cc )

When compiled with `-std=c++17 -O3` on trunk (r312894) generates a jump table,
each of which corresponds to a long-winded "return true" or "return false", of
the form:

.LBB0_2:
  mov eax, has_char(char)::a+42
  mov ecx, has_char(char)::a+42
  cmp rax, rcx
  setne al
  ret

This is equivalent to `xor eax, eax; ret`. On clang 5.0.0 and with -O2,
different code is generated:

.LBB0_8:
  mov eax, has_char(char)::a+41
  jmp .LBB0_19
....
.LBB0_19:
  mov ecx, has_char(char)::a+42
  cmp rax, rcx
  setne al
  ret

It seems like the code generator is only one step from inferring that each leaf
of the jump table can be replaced with xor eax,eax;ret, or `mov eax,1;ret`, but
falls at the final hurdle.

-- 
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