[llvm-bugs] [Bug 34196] New: c++14 cause worse codegen than c++1z.

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Aug 15 11:17:42 PDT 2017


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

            Bug ID: 34196
           Summary: c++14 cause worse codegen than c++1z.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: denis.yaroshevskij at gmail.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Created attachment 18988
  --> https://bugs.llvm.org/attachment.cgi?id=18988&action=edit
code

Hi.

I was playing with variant implementation and found out that c++1z option
produces a better code than with c++14. Might be worth looking into.

Unfortunately, links to goldbolt currently do not work, so I attach code as
file.

It's not exactly an easy read so quick idea:
for each possible combination of parameters, I instantiate a function. All of
this functions are written in one n-dimentional array, where each dimension
corresponds to an element.
So sum of two variants should be equivalent to:
  int sum(const variant<int, char>& x, const variant<char, int>& y) {
    using f_type = ...
    static const f_type vtable = {
      {
        [](decltype(x) x, decltype(y) y) -> int { 
           return get<0>(x) + get<0>(y); },
        [](decltype(x) x, decltype(y) y) -> int {
           return get<0>(x) + get<1>(y); },
      },
      {
        [](decltype(x) x, decltype(y) y) -> int {
           return get<1>(x) + get<0>(y); },
        [](decltype(x) x, decltype(y) y) -> int {
           return get<1>(x) + get<1>(y); },
      }
    };

    return vtable[x.idx][y.idx](x, y);
  }

Compiling with c++1z generates 2 times less instructions than with c++14. This
does not seem right.

Compilation options: -Werror -Wall --std=c++1z -O3 -fno-exceptions -DNDEBUG

-- 
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/20170815/36fc3ecb/attachment-0001.html>


More information about the llvm-bugs mailing list