public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: yourst@yourst.com
To: gcc-gnats@gcc.gnu.org
Cc: yourst@yourst.com
Subject: optimization/10623: Incorrect generation of IA-32 SSE movups via __builtin_ia32_loadups
Date: Sun, 04 May 2003 17:36:00 -0000	[thread overview]
Message-ID: <20030504172903.19538.qmail@sources.redhat.com> (raw)


>Number:         10623
>Category:       optimization
>Synopsis:       Incorrect generation of IA-32 SSE movups via __builtin_ia32_loadups
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun May 04 17:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Matt Yourst
>Release:        gcc 3.2.2
>Organization:
>Environment:
gcc from Mandrake Linux (release gcc-3.2.2-3mdk)
>Description:
When using the __builtin_ia32_loadups function, gcc generates incorrect code at all optimization levels including -O1. In some circumstances, gcc generates a "movaps" load instruction instead of the specified "movups"; the code will cause an unaligned SSE load exception when run.

Furthermore, if the (incorrectly) loaded vector is subsequently stored to another correctly aligned address, gcc places the "movups" there in place of the correct instruction, "movaps".

See below for code and commented disassembly.
>How-To-Repeat:
// Compile with gcc -O2 -msse -fomit-frame-pointer:

typedef float vec4f_t __attribute__ ((mode(V4SF)));

void test(vec4f_t* dest, float* src, int count) {
  for (int i = 0; i < count; i++) {
    vec4f_t v = __builtin_ia32_loadups(src + i);
    dest[i] = v;
  }
}

int main() {
  vec4f_t dest[64];
  float src[64];
  test(dest, src, 64-4);
}

/*

Dump of assembler code for function _Z4testPU8__vectorfPfi:
  mov    0xc(%esp,1),%eax
  test   %eax,%eax
  jle    0x80483ef <_Z4testPU8__vectorfPfi+31>
  mov    0x4(%esp,1),%ecx
  mov    0x8(%esp,1),%edx
  movaps (%edx),%xmm0       << INCORRECT: this should be movups (%edx),%xmm0
  movups %xmm0,(%ecx)       << INCORRECT: this should be movaps %xmm0,(%ecx)
  add    $0x4,%edx
  add    $0x10,%ecx
  dec    %eax
  jne    0x80483e0 <_Z4testPU8__vectorfPfi+16>
  ret

*/
>Fix:
Unknown; only workaround is to compile at -O0 or use inline assembly instead of __builtin_ia32_loadups intrinsic.
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2003-05-04 17:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-04 17:36 yourst [this message]
2003-05-10 19:36 Dara Hazeghi
2003-05-12 11:23 giovannibajo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030504172903.19538.qmail@sources.redhat.com \
    --to=yourst@yourst.com \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).