public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly
@ 2011-06-16 19:45 pinskia at gcc dot gnu.org
  2011-06-16 20:09 ` [Bug tree-optimization/49444] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-06-16 19:45 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: IV-OPTs changes an unaligned loads into aligned loads
                    incorrectly
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: pinskia@gcc.gnu.org


Take:
/* { dg-do compile { target mips*-*-* } } */
/* { dg-options "-O2" } */
/* { dg-final { scan-assembler "uld\\t|ldr\\t|lwr\\t" } } */


struct s
{
  unsigned int l;
  unsigned int z[2];
};

struct r
{
  char c;
  struct s s;
} __attribute__ ((packed));

struct s *ss;

f (struct r *p, int l)
{
  int i;
  for (i = 0; i < l; i++)
    {
      *ss = p[i].s;
      g ();
    }
}
--- CUT ---
Currently this fails and the load from p[i].s is turned into an aligned load.


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
@ 2011-06-16 20:09 ` rguenth at gcc dot gnu.org
  2011-06-16 20:16 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-16 20:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-16 20:08:43 UTC ---
Well, I'm 100% sure this is just the age-old bug that GCC can't expand
misaligned indirect-refs (or nowadays mem-refs and target-mem-refs) on
strict-align targets properly.

Try the following on any GCC version:

typedef int myint __attribute__((aligned(1)));

int foo(myint *p)
{
  return *p;
}
int main()
{
  char c[5] = {};
  return foo(&c[1]);
}

it'll fault on any strict-align target since forever.  Now it would
indeed be nice if _finally_ somebody would go and fix that ...

Dup of ....


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
  2011-06-16 20:09 ` [Bug tree-optimization/49444] " rguenth at gcc dot gnu.org
@ 2011-06-16 20:16 ` pinskia at gcc dot gnu.org
  2011-06-16 21:10 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-06-16 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-06-16 20:16:09 UTC ---
(In reply to comment #1)
> Well, I'm 100% sure this is just the age-old bug that GCC can't expand
> misaligned indirect-refs (or nowadays mem-refs and target-mem-refs) on
> strict-align targets properly.

This has nothing to do with the misalgined indirect-ref issue as it works when
IV-opts is disabled.


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
  2011-06-16 20:09 ` [Bug tree-optimization/49444] " rguenth at gcc dot gnu.org
  2011-06-16 20:16 ` pinskia at gcc dot gnu.org
@ 2011-06-16 21:10 ` pinskia at gcc dot gnu.org
  2011-06-17  9:06 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-06-16 21:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-06-16 21:10:18 UTC ---
Something like this:
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c    (revision 61384)
+++ tree-ssa-loop-ivopts.c    (working copy)
@@ -6066,6 +6066,8 @@ rewrite_use_address (struct ivopts_data
   tree base_hint = NULL_TREE;
   tree ref, iv;
   bool ok;
+  unsigned align;
+  tree type;

   adjust_iv_update_pos (cand, use);
   ok = get_computation_aff (data->current_loop, use, cand, use->stmt, &aff);
@@ -6087,7 +6089,10 @@ rewrite_use_address (struct ivopts_data
     base_hint = var_at_stmt (data->current_loop, cand, use->stmt);

   iv = var_at_stmt (data->current_loop, cand, use->stmt);
-  ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff,
+  align = get_object_alignment (*use->op_p, BIGGEST_ALIGNMENT);
+  type = TREE_TYPE (*use->op_p);
+  type = build_aligned_type (type, align);
+  ref = create_mem_ref (&bsi, type, &aff,
             reference_alias_ptr_type (*use->op_p),
             iv, base_hint, data->speed);
   copy_ref_info (ref, *use->op_p);


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-06-16 21:10 ` pinskia at gcc dot gnu.org
@ 2011-06-17  9:06 ` rguenth at gcc dot gnu.org
  2011-06-17 16:25 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-06-17  9:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-06-17 09:06:22 UTC ---
(In reply to comment #3)
> Something like this:
> Index: tree-ssa-loop-ivopts.c
> ===================================================================
> --- tree-ssa-loop-ivopts.c    (revision 61384)
> +++ tree-ssa-loop-ivopts.c    (working copy)
> @@ -6066,6 +6066,8 @@ rewrite_use_address (struct ivopts_data
>    tree base_hint = NULL_TREE;
>    tree ref, iv;
>    bool ok;
> +  unsigned align;
> +  tree type;
> 
>    adjust_iv_update_pos (cand, use);
>    ok = get_computation_aff (data->current_loop, use, cand, use->stmt, &aff);
> @@ -6087,7 +6089,10 @@ rewrite_use_address (struct ivopts_data
>      base_hint = var_at_stmt (data->current_loop, cand, use->stmt);
> 
>    iv = var_at_stmt (data->current_loop, cand, use->stmt);
> -  ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff,
> +  align = get_object_alignment (*use->op_p, BIGGEST_ALIGNMENT);
> +  type = TREE_TYPE (*use->op_p);
> +  type = build_aligned_type (type, align);
> +  ref = create_mem_ref (&bsi, type, &aff,
>              reference_alias_ptr_type (*use->op_p),
>              iv, base_hint, data->speed);
>    copy_ref_info (ref, *use->op_p);

Well, that will then still run into the indirect-ref issue as
the expansion for target-mem-refs and mem-refs works the same way.
Only targets that support movmisalign will generate unaligned
loads (which targets currently only define for vector modes I think).


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-06-17  9:06 ` rguenth at gcc dot gnu.org
@ 2011-06-17 16:25 ` pinskia at gcc dot gnu.org
  2011-12-16  0:36 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-06-17 16:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-06-17 16:25:04 UTC ---
(In reply to comment #4)
> 
> Well, that will then still run into the indirect-ref issue as
> the expansion for target-mem-refs and mem-refs works the same way.
> Only targets that support movmisalign will generate unaligned
> loads (which targets currently only define for vector modes I think).

It works in the case which I reported because the mode is BLKmode.  I tried to
get a testcase that would still fail after this but I could not find one as
IV-OPTs would use a->b for that still.

Thanks,
Andrew Pinski


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-06-17 16:25 ` pinskia at gcc dot gnu.org
@ 2011-12-16  0:36 ` pinskia at gcc dot gnu.org
  2011-12-16  8:02 ` ebotcazou at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-12-16  0:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-12-16 00:33:10 UTC ---
This is the patch which I ended up with:
Index: tree-ssa-loop-ivopts.c
===================================================================
--- tree-ssa-loop-ivopts.c    (revision 61449)
+++ tree-ssa-loop-ivopts.c    (revision 61858)
@@ -6066,6 +6066,7 @@ rewrite_use_address (struct ivopts_data
   tree base_hint = NULL_TREE;
   tree ref, iv;
   bool ok;
+  tree type;

   adjust_iv_update_pos (cand, use);
   ok = get_computation_aff (data->current_loop, use, cand, use->stmt, &aff);
@@ -6087,7 +6088,13 @@ rewrite_use_address (struct ivopts_data
     base_hint = var_at_stmt (data->current_loop, cand, use->stmt);

   iv = var_at_stmt (data->current_loop, cand, use->stmt);
-  ref = create_mem_ref (&bsi, TREE_TYPE (*use->op_p), &aff,
+  type = TREE_TYPE (*use->op_p);
+  if (TREE_CODE (*use->op_p) == COMPONENT_REF)
+    {
+      unsigned align = DECL_ALIGN (TREE_OPERAND (*use->op_p, 1));
+      type = build_aligned_type (type, align);
+    }
+  ref = create_mem_ref (&bsi, type, &aff,
             reference_alias_ptr_type (*use->op_p),
             iv, base_hint, data->speed);
   copy_ref_info (ref, *use->op_p);
--- CUT ---
I also implemented on mips the misalignedmove patterns too.


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2011-12-16  0:36 ` pinskia at gcc dot gnu.org
@ 2011-12-16  8:02 ` ebotcazou at gcc dot gnu.org
  2014-09-03 10:11 ` amker.cheng at gmail dot com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2011-12-16  8:02 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2011-12-16
                 CC|                            |ebotcazou at gcc dot
                   |                            |gnu.org
     Ever Confirmed|0                           |1

--- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2011-12-16 07:46:00 UTC ---
> Currently this fails and the load from p[i].s is turned into an aligned load.

This is an old issue with IVOPTS which is supposed to have been fixed long ago
by means of the may_be_unaligned_p predicate.  Why is it apparently bypassed
here?


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2011-12-16  8:02 ` ebotcazou at gcc dot gnu.org
@ 2014-09-03 10:11 ` amker.cheng at gmail dot com
  2014-09-03 11:07 ` rguenth at gcc dot gnu.org
  2014-09-03 12:27 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: amker.cheng at gmail dot com @ 2014-09-03 10:11 UTC (permalink / raw)
  To: gcc-bugs

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

bin.cheng <amker.cheng at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amker.cheng at gmail dot com

--- Comment #8 from bin.cheng <amker.cheng at gmail dot com> ---
This should be fixed on trunk now.  At least for r211210 and r214864.
For Andrew's test, the generated mips assmbly for kernel loop is as below.

$L3:
    lwl    $5,1($16)
    lwl    $4,5($16)
    lwl    $3,9($16)
    lwr    $5,4($16)
    lwr    $4,8($16)
    lwr    $3,12($16)
    lw    $2,%gp_rel(ss)($28)
    addiu    $16,$16,13
    sw    $5,0($2)
    sw    $4,4($2)
    jal    g
    sw    $3,8($2)

    bne    $16,$17,$L3
    move    $2,$0

For Richard's case (with an explicit conversion when calling foo), the
generated mips assembly is as below.
foo:
    .frame    $sp,0,$31        # vars= 0, regs= 0/0, args= 0, gp= 0
    .mask    0x00000000,0
    .fmask    0x00000000,0
    .set    noreorder
    .set    nomacro
    lwl    $2,0($4)
    nop
    lwr    $2,3($4)
    j    $31
    nop

    .set    macro
    .set    reorder
    .end    foo
    .size    foo, .-foo

Apparently, lwl/lwr are generated for unalgned memory access.

Thanks,
bin


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2014-09-03 10:11 ` amker.cheng at gmail dot com
@ 2014-09-03 11:07 ` rguenth at gcc dot gnu.org
  2014-09-03 12:27 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-09-03 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Thus "dup" of PR61320?


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

* [Bug tree-optimization/49444] IV-OPTs changes an unaligned loads into aligned loads incorrectly
  2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2014-09-03 11:07 ` rguenth at gcc dot gnu.org
@ 2014-09-03 12:27 ` pinskia at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-09-03 12:27 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #9)
> Thus "dup" of PR61320?

Yes.

*** This bug has been marked as a duplicate of bug 61320 ***


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

end of thread, other threads:[~2014-09-03 12:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-16 19:45 [Bug tree-optimization/49444] New: IV-OPTs changes an unaligned loads into aligned loads incorrectly pinskia at gcc dot gnu.org
2011-06-16 20:09 ` [Bug tree-optimization/49444] " rguenth at gcc dot gnu.org
2011-06-16 20:16 ` pinskia at gcc dot gnu.org
2011-06-16 21:10 ` pinskia at gcc dot gnu.org
2011-06-17  9:06 ` rguenth at gcc dot gnu.org
2011-06-17 16:25 ` pinskia at gcc dot gnu.org
2011-12-16  0:36 ` pinskia at gcc dot gnu.org
2011-12-16  8:02 ` ebotcazou at gcc dot gnu.org
2014-09-03 10:11 ` amker.cheng at gmail dot com
2014-09-03 11:07 ` rguenth at gcc dot gnu.org
2014-09-03 12:27 ` pinskia 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).