[LLVMbugs] [Bug 22896] New: [loop vectorize] Simple loop calculation on signed chars does not vectorize

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Mar 13 10:16:11 PDT 2015


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

            Bug ID: 22896
           Summary: [loop vectorize] Simple loop calculation on signed
                    chars does not vectorize
           Product: libraries
           Version: trunk
          Hardware: Other
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: wschmidt at linux.vnet.ibm.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

A very simple test case is not vectorized, at least for powerpc64le.

void abort();

#define N 16

signed char ca[N] __attribute__((aligned(16)));
signed char cb[] __attribute__((aligned(16)))
  = {8, 7, 6, 5, 4, 3, 2,  1,  0, -1, -2, -3, -4, -5, -6, -7};
signed char cc[] __attribute__((aligned(16)))
  = {1, 1, 2, 2, 3, 3, 2,  2,  1,  1,  0,  0, -1, -1, -2, -2};

__attribute__((noinline)) void foo ()
{
  int i;
  for (i = 0; i < N; i++) {
    ca[i] = cb[i] - cc[i];
  }
}

int main ()
{
  signed char cd[] = {7, 6, 4, 3, 1, 0, 0, -1, -1, -2, -2, -3, -3, -4, -4, -5};
  int i;
  foo ();
  for (i = 0; i < N; ++i)
    if (ca[i] != cd[i])
      abort ();
  return 0;
}

Compiling with -O3 -target powerpc64le-unknown-linux-gnu -S produces this as
the core loop in foo():

.LBB0_1:                                # %for.body
                                        # =>This Inner Loop Header: Depth=1
        lbzu 6, 4(5)
        lbzu 7, 4(4)
        lbz 8, 1(5)
        lbz 10, 2(5)
        lbz 12, 3(5)
        lbz 9, 1(4)
        lbz 11, 2(4)
        lbz 0, 3(4)
        subf 6, 7, 6
        stbu 6, 4(3)
        subf 9, 9, 8
        subf 11, 11, 10
        subf 12, 0, 12
        stb 9, 1(3)
        stb 11, 2(3)
        stb 12, 3(3)
        bdnz .LBB0_1

GCC, though, fully unrolls the loop and generates vectorized code (address
setup code omitted):

        lxvd2x 32,0,9
        lxvd2x 33,9,10
        vsububm 0,0,1
        stxvd2x 32,0,9

Methinks we should do that, too. ;)

CCing Hal and Kit.  Hal, Kit is interested in looking at this as a learning
activity, so no need to jump on this unless you feel it can't wait.

-- 
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/20150313/a4222a31/attachment.html>


More information about the llvm-bugs mailing list