[llvm-bugs] [Bug 34554] New: Code generation regression with trunk
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Sep 11 07:14:12 PDT 2017
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: unassignedclangbugs at nondot.org
Reporter: matt at godbolt.org
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170911/e935b366/attachment.html>
More information about the llvm-bugs
mailing list