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 tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs
Date: Tue, 12 Apr 2011 12:20:00 -0000	[thread overview]
Message-ID: <bug-48571-4@http.gcc.gnu.org/bugzilla/> (raw)

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

           Summary: Missed data-dependence for (bogus?) reconstructed
                    array-refs
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rguenth@gcc.gnu.org
            Target: i?86-*-*


We vectorize the following loop, ignoring dependences between c[i] and c[i-1].

unsigned int c[624];
void
bar (void)
{
  unsigned int i;
  for (i = 1; i < 624; ++i)
    /* Obfuscated c[i] = c[i-1] * 2.  */
    *(unsigned int *)((void *)c + (__SIZE_TYPE__)i * 4)
        = *(unsigned int *)((void *)c + ((__SIZE_TYPE__)i +
((__SIZE_TYPE__)-4)/4) * 4) * 2;
}

This is because we re-construct array-refs

<bb 3>:
  # i_17 = PHI <i_12(4), 1(2)>
  # ivtmp.8_21 = PHI <ivtmp.8_20(4), 623(2)>
  D.2689_3 = (long unsigned int) i_17;
  D.2692_7 = D.2689_3 + 1073741823;
  D.2695_10 = MEM[(unsigned int *)&c][D.2692_7]{lb: 0 sz: 4};
  D.2696_11 = D.2695_10 * 2;
  MEM[(unsigned int *)&c][D.2689_3]{lb: 0 sz: 4} = D.2696_11;

and the array index D.2692_7 is out of bounds (but of course the address
computation will make the access wrap into the correct place).

The middle-end happily performs such obfuscation via
fold_plusminus_mult_expr from (i*4 + -4U).
The array-refs are re-built by forwprop.

I'm not sure who is wrong here - bogus constrained interpretation of
array-refs by data dependence analysis or bogus construction of
constrained array-refs from pointer arithmetic.

Executable testcase, x86_64, -O3 -msse2 -m32:

unsigned int c[624];
void __attribute__((noinline))
bar (void)
{
  unsigned int i;
  /* Obfuscated c[i] = c[i-1] * 2.  */
  for (i = 1; i < 624; ++i)
    *(unsigned int *)((void *)c + (__SIZE_TYPE__)i * 4)
        = 2 * *(unsigned int *)((void *)c + ((__SIZE_TYPE__)i +
((__SIZE_TYPE__)-4)/4) * 4);
}
extern void abort (void);
int
main()
{
  unsigned int i, j;
  for (i = 0; i < 624; ++i)
    c[i] = 1;
  bar();
  j = 1;
  for (i = 0; i < 624; ++i)
    {
      if (c[i] != j)
        abort ();
      j = j * 2;
    }
  return 0;
}


             reply	other threads:[~2011-04-12 12:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12 12:20 rguenth at gcc dot gnu.org [this message]
2011-04-12 12:21 ` [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] " rguenth at gcc dot gnu.org
2011-04-12 12:25 ` rguenth at gcc dot gnu.org
2011-04-12 13:12 ` rguenth at gcc dot gnu.org
2011-04-21  9:26 ` rguenth at gcc dot gnu.org
2011-04-28 15:39 ` rguenth at gcc dot gnu.org
2011-08-30 12:22 ` rguenth at gcc dot gnu.org
2011-08-30 14:09 ` rguenth at gcc dot gnu.org
2011-08-30 14:15 ` [Bug tree-optimization/48571] [4.5/4.6 " rguenth at gcc dot gnu.org
2011-09-05 11:43 ` gjl at gcc dot gnu.org
2011-09-07 17:36 ` gjl at gcc dot gnu.org
2012-01-03 12:15 ` rguenth 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-48571-4@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).