public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs
@ 2011-04-12 12:20 rguenth at gcc dot gnu.org
  2011-04-12 12:21 ` [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-12 12:20 UTC (permalink / raw)
  To: gcc-bugs

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;
}


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
@ 2011-04-12 12:21 ` rguenth at gcc dot gnu.org
  2011-04-12 12:25 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-12 12:21 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.4.4
   Target Milestone|---                         |4.5.3
            Summary|Missed data-dependence for  |[4.5/4.6/4.7 Regression]
                   |(bogus?) reconstructed      |Missed data-dependence for
                   |array-refs                  |(bogus?) reconstructed
                   |                            |array-refs
      Known to fail|                            |4.5.2, 4.6.0, 4.7.0


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
  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
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-12 12:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-12 12:24:46 UTC ---
To also fail for 64bit change it to

  for (i = 1; i < 624; ++i)
    {
      __SIZE_TYPE__ ii = (__SIZE_TYPE__)i + ((__SIZE_TYPE__)-4)/4;
      *(unsigned int *)((void *)c + (__SIZE_TYPE__)i * 4)
          = 2 * *(unsigned int *)((void *)c + ii * 4);
    }

to prevent fold from pulling the multiplication inside.


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
  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
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-12 13:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-12 13:11:56 UTC ---
Re-constructing array-refs (and thus an index space) is invalid.  Which means
the C frontend should better change its behavior and not lower all array
accesses to pointer arithmetic and dereferences.


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-21  9:26 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-04-28 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.5.3                       |4.5.4

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-04-28 14:51:51 UTC ---
GCC 4.5.3 is being released, adjusting target milestone.


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-30 12:22 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2011-08-30
         AssignedTo|unassigned at gcc dot       |rguenth at gcc dot gnu.org
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-30 11:42:59 UTC ---
Mine.


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

* [Bug tree-optimization/48571] [4.5/4.6/4.7 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-30 14:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-30 14:06:07 UTC ---
Author: rguenth
Date: Tue Aug 30 14:06:00 2011
New Revision: 178312

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178312
Log:
2011-08-30  Richard Guenther  <rguenther@suse.de>

    PR middle-end/48571
    * gimple.h (maybe_fold_offset_to_address): Remove.
    (maybe_fold_offset_to_reference): Likewise.
    (maybe_fold_stmt_addition): Likewise.
    (may_propagate_address_into_dereference): Likewise.
    * tree-inline.c (remap_gimple_op_r): Do not reconstruct
    array references.
    * gimple-fold.c (canonicalize_constructor_val): Likewise.
    Canonicalize invariant POINTER_PLUS_EXPRs to invariant MEM_REF
    addresses instead.
    (may_propagate_address_into_dereference): Remove.
    (maybe_fold_offset_to_array_ref): Likewise.
    (maybe_fold_offset_to_reference): Likewise.
    (maybe_fold_offset_to_address): Likewise.
    (maybe_fold_stmt_addition): Likewise.
    (fold_gimple_assign): Do not reconstruct array references but
    instead canonicalize invariant POINTER_PLUS_EXPRs to invariant
    MEM_REF addresses.
    (gimple_fold_stmt_to_constant_1): Likewise.
    * tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Likewise.
    * gimplify.c (gimplify_conversion): Likewise.
    (gimplify_expr): Likewise.

    * gcc.c-torture/execute/pr48571-1.c: New testcase.
    * gcc.dg/tree-ssa/ssa-ccp-25.c: Remove.
    * gcc.dg/tree-ssa/ssa-ccp-26.c: Likewise.
    * gcc.dg/pr36902.c: XFAIL.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr48571-1.c
Removed:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-25.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-26.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c
    trunk/gcc/gimple.h
    trunk/gcc/gimplify.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/pr36902.c
    trunk/gcc/tree-inline.c
    trunk/gcc/tree-ssa-forwprop.c


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

* [Bug tree-optimization/48571] [4.5/4.6 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2011-08-30 14:09 ` rguenth at gcc dot gnu.org
@ 2011-08-30 14:15 ` rguenth at gcc dot gnu.org
  2011-09-05 11:43 ` gjl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-08-30 14:15 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.7.0
            Summary|[4.5/4.6/4.7 Regression]    |[4.5/4.6 Regression] Missed
                   |Missed data-dependence for  |data-dependence for
                   |(bogus?) reconstructed      |(bogus?) reconstructed
                   |array-refs                  |array-refs
      Known to fail|4.7.0                       |

--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-08-30 14:07:03 UTC ---
Fixed for 4.7.  There is not much chance in backporting.


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

* [Bug tree-optimization/48571] [4.5/4.6 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  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
  10 siblings, 0 replies; 12+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-09-05 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gjl at gcc dot gnu.org

--- Comment #7 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-09-05 11:43:00 UTC ---
(In reply to comment #5)

>     * gcc.c-torture/execute/pr48571-1.c: New testcase.

This new test case fails execution for all optimization levels on AVR; appears
the test case misses

/* { dg-require-effective-target int32plus } */

or similar.


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

* [Bug tree-optimization/48571] [4.5/4.6 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  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
  10 siblings, 0 replies; 12+ messages in thread
From: gjl at gcc dot gnu.org @ 2011-09-07 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Georg-Johann Lay <gjl at gcc dot gnu.org> 2011-09-07 17:31:08 UTC ---
Author: gjl
Date: Wed Sep  7 17:31:01 2011
New Revision: 178655

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=178655
Log:
    PR middle-end/48571
    * gcc.c-torture/execute/pr48571-1.c (bar): Use offsets sizeof(int)
    instead of 4.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.c-torture/execute/pr48571-1.c


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

* [Bug tree-optimization/48571] [4.5/4.6 Regression] Missed data-dependence for (bogus?) reconstructed array-refs
  2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2011-09-07 17:36 ` gjl at gcc dot gnu.org
@ 2012-01-03 12:15 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-01-03 12:15 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.5.4                       |4.7.0

--- Comment #9 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-03 12:14:47 UTC ---
Fixed for trunk, no backporting possible.


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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-12 12:20 [Bug tree-optimization/48571] New: Missed data-dependence for (bogus?) reconstructed array-refs rguenth at gcc dot gnu.org
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

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).