public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/94482] Inserting into vector with optimization enabled on x86 generates incorrect result
Date: Mon, 06 Apr 2020 07:20:48 +0000	[thread overview]
Message-ID: <bug-94482-4-3g5dxfs3pq@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94482-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94482

--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Martin Liška from comment #9)
> (In reply to Evan Nemerson from comment #8)
> > Created attachment 48204 [details]
> > Reduced test case, ASan/UBSan clean
> > 
> > Here is the reduced test case which works with -fsanitize=address,undefined
> > -Wno-psabi -Wall -Werror.
> > 
> > This one is self-contained, and instead of using assert the return value is
> > 0 on success and 1 on failure.
> 
> Thank you.
> The git bisection revisions remain the same for the reduced test-case.
> Isn't the problem right now the violation of -Wpsabi?
> 
> pr94482-v2.c: In function ‘s’:
> pr94482-v2.c:8:1: warning: SSE vector return without SSE enabled changes the
> ABI [-Wpsabi]
>     8 | l s(__INT64_TYPE__ a) {
>       | ^
> pr94482-v2.c: In function ‘p’:
> pr94482-v2.c:16:3: note: the ABI for passing parameters with 16-byte
> alignment has changed in GCC 4.6
>    16 | l p(l a, __INT64_TYPE__ i, int q) {
>       |   ^
> pr94482-v2.c:16:3: warning: SSE vector argument without SSE enabled changes
> the ABI [-Wpsabi]

No, that's not an issue here.  All of the code is inlined into main anyways,
with -fno-inline the code is fine.  Making the two non-main functions static
makes the testcase easier to look at.  You can see after inlining the IL
has lots of redundancies that should be irrelevant but GIMPLE IL support
is too limited on the GCC 9 branch to do that editing there.

The assembly shows:

        movl    16(%esp), %eax
        movl    20(%esp), %edx
...
        xorl    $1729, %eax
        orl     %edx, %eax
        setne   %al

which is the final comparison but those stack slots are never written to.

If you look at the GIMPLE before RTL expansion it looks like

main ()
{
  union k r_;
  vector(4) int n;
  union k r_;
  vector(4) int n;
  long long int _1;
  _Bool _2;
  int _6;
  vector(4) int _18;
  vector(4) int _20;

;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  BIT_FIELD_REF <r_.i64, 64, 0> = 1729;
  _18 = MEM[(union  *)&r_];
  MEM[(char * {ref-all})&m] = _18;
  n = _18;
  MEM[(char * {ref-all})&u] = MEM[(char * {ref-all})&n];
  BIT_FIELD_REF <r_.i64, 64, 64> = 2;
  _20 = MEM[(union  *)&r_];
  MEM[(char * {ref-all})&v] = _20;
  o = _20;
  n ={v} {CLOBBER};
  n = _20;
  MEM[(char * {ref-all})&t] = MEM[(char * {ref-all})&n];
  _1 = BIT_FIELD_REF <_20, 64, 0>;
  _2 = _1 != 1729;
  _6 = (int) _2;
  n ={v} {CLOBBER};
  return _6;
;;    succ:       EXIT

but the body should be simplifiable to just

  BIT_FIELD_REF <r_.i64, 64, 0> = 1729;
  BIT_FIELD_REF <r_.i64, 64, 64> = 2;
  _20 = MEM[(union  *)&r_];
  _1 = BIT_FIELD_REF <_20, 64, 0>;
  _2 = _1 != 1729;
  _6 = (int) _2;
  return _6;

of course the unrelated stmts may actually trigger the miscompile.  GCC 9
does not have BIT_FIELD_REF support for the GIMPLE FE (but it should be
backportable I guess).

  parent reply	other threads:[~2020-04-06  7:20 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-03 22:40 [Bug target/94482] New: " evan@coeus-group.com
2020-04-04  9:36 ` [Bug target/94482] " marxin at gcc dot gnu.org
2020-04-04 17:33 ` evan@coeus-group.com
2020-04-04 21:44 ` ubizjak at gmail dot com
2020-04-04 21:50 ` ubizjak at gmail dot com
2020-04-05 14:44 ` marxin at gcc dot gnu.org
2020-04-05 14:46 ` marxin at gcc dot gnu.org
2020-04-05 21:08 ` evan@coeus-group.com
2020-04-05 22:19 ` evan@coeus-group.com
2020-04-06  6:35 ` marxin at gcc dot gnu.org
2020-04-06  6:47 ` jakub at gcc dot gnu.org
2020-04-06  6:55 ` marxin at gcc dot gnu.org
2020-04-06  7:14 ` jakub at gcc dot gnu.org
2020-04-06  7:20 ` rguenth at gcc dot gnu.org [this message]
2020-04-06  7:28 ` [Bug target/94482] [8/9/10 Regression] " jakub at gcc dot gnu.org
2020-04-06  7:29 ` marxin at gcc dot gnu.org
2020-04-06  7:30 ` jakub at gcc dot gnu.org
2020-04-06  8:32 ` rguenth at gcc dot gnu.org
2020-04-06  8:44 ` rguenth at gcc dot gnu.org
2020-04-06  8:54 ` rguenth at gcc dot gnu.org
2020-04-06  9:32 ` rguenth at gcc dot gnu.org
2020-04-06 12:59 ` [Bug tree-optimization/94482] " rguenth at gcc dot gnu.org
2020-04-06 13:40 ` jamborm at gcc dot gnu.org
2020-04-06 16:36 ` rguenth at gcc dot gnu.org
2020-04-09 12:43 ` cvs-commit at gcc dot gnu.org
2020-04-09 12:46 ` [Bug tree-optimization/94482] [8/9 " jamborm at gcc dot gnu.org
2020-04-10  3:39 ` evan@coeus-group.com
2020-04-11  5:51 ` cvs-commit at gcc dot gnu.org
2020-04-21 12:22 ` cvs-commit at gcc dot gnu.org
2020-04-21 15:42 ` cvs-commit at gcc dot gnu.org
2020-04-21 16:37 ` jamborm at gcc dot gnu.org

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=bug-94482-4-3g5dxfs3pq@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).