[llvm-bugs] [Bug 28886] New: Loads from array into small struct are not fused.

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 6 13:29:42 PDT 2016


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

            Bug ID: 28886
           Summary: Loads from array into small struct are not fused.
           Product: new-bugs
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: edy.burt at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

>From the included testcase, only the fourth function is optimal - a single
unaligned load of i16, "movzx eax, word ptr [rdi]".
The other functions load the two bytes separately and pack them with shl and
or.

I believe it has to do with the fourth function using llvm.memcpy, which
somehow takes precedence over the individual loads and everything is kept as
one i16. 

On IRC "-mllvm -combine-loads" was suggested, which does turn the first three
functions into the same single i16 load as the fourth, but I've also been told
that it causes regressions in other situations so it's not enabled by default.

---

#include <array>

using namespace std;

typedef unsigned char i8;

struct XY { i8 x, y; };

XY direct(array<i8, 2> &a) {
  return {a[0], a[1]};
}

XY vars(array<i8, 2> &a) {
  i8 x = a[0], y = a[1];
  return {x, y};
}

XY array(array<i8, 2> &a) {
  array<i8, 2> b;
  b[0] = a[0];
  b[1] = a[1];
  return {b[0], b[1]};
}

XY array_llvm_memcpy(array<i8, 2> &a) {
  array<i8, 2> b;
  b = a;
  return {b[0], b[1]};
}

-- 
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/20160806/a5cf3e4b/attachment.html>


More information about the llvm-bugs mailing list