public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/50162] New: Wrong vectorization
@ 2011-08-23  8:03 ubizjak at gmail dot com
  2011-08-23  8:14 ` [Bug tree-optimization/50162] [4.7 Regression] " ubizjak at gmail dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: ubizjak at gmail dot com @ 2011-08-23  8:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50162

             Bug #: 50162
           Summary: Wrong vectorization
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ubizjak@gmail.com
            Target: x86


Following testcase results in wrong vectorization:

--cut here--
double a[256];
int b[256];
unsigned short c[256];

extern long lrint (double);

void bar(void)
{
  int i;

  for (i=0; i<256; ++i)
    {
      b[i] = lrint (a[i]);
      c[i] += c[i];
    }
}
--cut here--

gcc -O2 -ffast-math -ftree-vectorize -m32 -msse2 -mfpmath=sse

.L2:
    cvtpd2dq    a+16(,%eax,4), %xmm0
    cvtpd2dq    a(,%eax,4), %xmm1
    cvtpd2dq    a+32(,%eax,4), %xmm2
    punpcklqdq    %xmm0, %xmm1
    punpcklqdq    %xmm2, %xmm0
    movdqa    %xmm0, b+16(%eax,%eax)
    movdqa    c(%eax), %xmm0
    paddw    %xmm0, %xmm0
    movdqa    %xmm1, b(%eax,%eax)
    movdqa    %xmm0, c(%eax)
    addl    $16, %eax
    cmpl    $512, %eax
    jne    .L2

One cvtpd2dq is missing.

4.6.1. compiles to:

.L2:
    cvtpd2dq    a+16(,%eax,4), %xmm0
    cvtpd2dq    a(,%eax,4), %xmm1
    cvtpd2dq    a+48(,%eax,4), %xmm2
    punpcklqdq    %xmm0, %xmm1
    cvtpd2dq    a+32(,%eax,4), %xmm0
    punpcklqdq    %xmm2, %xmm0
    movdqa    %xmm0, b+16(%eax,%eax)
    movdqa    c(%eax), %xmm0
    paddw    %xmm0, %xmm0
    movdqa    %xmm1, b(%eax,%eax)
    movdqa    %xmm0, c(%eax)
    addl    $16, %eax
    cmpl    $512, %eax
    jne    .L2

The problem is already in .optimized tree dump:

  vect_var_.13_22 = MEM[symbol: a, index: ivtmp.41_17, step: 4, offset: 0B];
  vect_var_.14_24 = MEM[symbol: a, index: ivtmp.41_17, step: 4, offset: 16B];
  vect_var_.15_26 = MEM[symbol: a, index: ivtmp.41_17, step: 4, offset: 32B];
  vect_var_.17_29 = __builtin_ia32_vec_pack_sfix (vect_var_.13_22,
vect_var_.14_24);
  vect_var_.17_30 = __builtin_ia32_vec_pack_sfix (vect_var_.14_24,
vect_var_.15_26);
  MEM[symbol: b, index: ivtmp.41_17, step: 2, offset: 0B] = vect_var_.17_29;
  MEM[symbol: b, index: ivtmp.41_17, step: 2, offset: 16B] = vect_var_.17_30;
  vect_var_.26_38 = MEM[symbol: c, index: ivtmp.41_17, offset: 0B];
  vect_var_.27_39 = vect_var_.26_38 + vect_var_.26_38;
  MEM[symbol: c, index: ivtmp.41_17, offset: 0B] = vect_var_.27_39;

Please note, there is no access to offset 48B.

Gcc 4.6.1 generates:

  vect_var_.39 = __builtin_ia32_vec_pack_sfix (MEM[symbol: a, index: ivtmp.69,
step: 4], MEM[symbol: a, index: ivtmp.69, step: 4, offset: 16]);
  vect_var_.77 = __builtin_ia32_vec_pack_sfix (MEM[symbol: a, index: ivtmp.69,
step: 4, offset: 32], MEM[symbol: a, index: ivtmp.69, step: 4, offset: 48]);
  MEM[symbol: b, index: ivtmp.69, step: 2] = vect_var_.39;
  MEM[symbol: b, index: ivtmp.69, step: 2, offset: 16] = vect_var_.77;
  vect_var_.52 = MEM[symbol: c, index: ivtmp.69];
  MEM[symbol: c, index: ivtmp.69] = [plus_expr] vect_var_.52 + vect_var_.52;


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-01-03 13:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-23  8:03 [Bug tree-optimization/50162] New: Wrong vectorization ubizjak at gmail dot com
2011-08-23  8:14 ` [Bug tree-optimization/50162] [4.7 Regression] " ubizjak at gmail dot com
2011-08-23  8:53 ` rguenth at gcc dot gnu.org
2011-08-23  8:55 ` rguenth at gcc dot gnu.org
2011-08-23  8:58 ` [Bug tree-optimization/50162] [4.5/4.6/4.7 " rguenth at gcc dot gnu.org
2011-08-23  9:16 ` rguenth at gcc dot gnu.org
2011-08-23 10:22 ` [Bug tree-optimization/50162] [4.5/4.6 " rguenth at gcc dot gnu.org
2011-08-23 10:38 ` [Bug tree-optimization/50162] [4.5/4.6/4.7 " rguenth at gcc dot gnu.org
2011-09-08  9:24 ` [Bug tree-optimization/50162] [4.5/4.6 " rguenth at gcc dot gnu.org
2011-09-08 10:02 ` [Bug tree-optimization/50162] [4.5 " rguenth at gcc dot gnu.org
2012-01-03 13:19 ` rguenth at gcc dot gnu.org
2012-01-03 13:21 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).