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: unassignedb...@nondot.org
          Reporter: edy.b...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to