public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
@ 2022-01-21 13:01 rguenth at gcc dot gnu.org
  2022-01-21 13:01 ` [Bug tree-optimization/104162] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-21 13:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104162
           Summary: [12 Regression] Missed CSE after lowering of
                    &MEM[ptr_1 + CST]
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rguenth at gcc dot gnu.org
  Target Milestone: ---

In the testcase of PR99673 we can see

  <bb 2> [local count: 1073741824]:
  _13 = &MEM[(struct B *)pc_2(D) + 1B].i;
  .ASAN_CHECK (6, _13, 4, 4);
  _1 = MEM[(struct B *)pc_2(D) + 1B].i;
  _14 = &pd_4(D)->i;
  .ASAN_CHECK (7, _14, 4, 4);
  pd_4(D)->i = _1;
  _9 = (sizetype) i_6(D);
  _10 = _9 * 16;
  _11 = _10 + 4;
  _12 = pc_2(D) + 1;
  psa_7 = _12 + _11;
  f (psa_7);

and FRE5 is not CSEing _12 to _13.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
@ 2022-01-21 13:01 ` rguenth at gcc dot gnu.org
  2022-01-21 13:13 ` rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-21 13:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Target Milestone|---                         |12.0
     Ever confirmed|0                           |1
                 CC|                            |pinskia at gcc dot gnu.org
   Last reconfirmed|                            |2022-01-21
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
  2022-01-21 13:01 ` [Bug tree-optimization/104162] " rguenth at gcc dot gnu.org
@ 2022-01-21 13:13 ` rguenth at gcc dot gnu.org
  2022-01-21 16:10 ` pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-21 13:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Testcase that did not regress:

struct S { int i; };

void foo (int *);

void bar (char *p)
{
  foo (&((struct S *)(p + 1))->i);
  foo ((int *)(p + 1));
}

Testcase that did regress (use -fgimple):

struct S { int i; };

void foo (int *);

void __GIMPLE (ssa)
bar (char * p)
{
  int * D_1997;
  int * _2;
  char * _3;

  __BB(2):
  _2 = &__MEM <struct S> ((struct S *)p_5(D) + _Literal (struct S *) 1).i;
  foo (_2);
  _3 = &__MEM <int> ((struct S *)p_5(D) + _Literal (struct S *)1);
  foo (_3);
  return;
}

it regressed because forwprop now rewrites one of the &MEMs:

--- t.c.033t.ccp1       2022-01-21 14:12:01.392883591 +0100
+++ t.c.034t.forwprop1  2022-01-21 14:12:01.392883591 +0100
@@ -10,7 +10,7 @@
   <bb 2> :
   _2_6 = &MEM[(struct S *)p_5(D) + 1B].i;
   foo (_2_6);
-  _3_9 = &MEM[(struct S *)p_5(D) + 1B];
+  _3_9 = p_5(D) + 1;
   foo (_3_9);
   return;

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
  2022-01-21 13:01 ` [Bug tree-optimization/104162] " rguenth at gcc dot gnu.org
  2022-01-21 13:13 ` rguenth at gcc dot gnu.org
@ 2022-01-21 16:10 ` pinskia at gcc dot gnu.org
  2022-01-24  9:50 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-21 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Right my original version of the lowering handled this. I guess we need to
handle the case where we have a handled reference too. But that would regress
PR 99673 again. I will take a look this weekend.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-01-21 16:10 ` pinskia at gcc dot gnu.org
@ 2022-01-24  9:50 ` rguenth at gcc dot gnu.org
  2022-01-26 13:48 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-24  9:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Btw, in VN it would be nice to handle

struct S { int i; };

int i;
int bar (char *p)
{
  char *q = p + 1;
  i = 1;
  char *r = (char *)&(((struct S *)&p[i])->i);
  return q == r;
}

the main issue here is that this is vn_reference vs. vn_nary handling and this
transitions from vn_reference to possibly vn_nary with valueization.  For VN
&MEM[p + 1] was more canonical and we could go back to this when seeing
pointer-plus -- at least when lookup & simplification does not produce a
redundancy.

Handling this in VN only and only when inlining is complete might also avoid
regressing the testcase again.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-01-24  9:50 ` rguenth at gcc dot gnu.org
@ 2022-01-26 13:48 ` rguenth at gcc dot gnu.org
  2022-01-26 14:39 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-26 13:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #4)
> Btw, in VN it would be nice to handle
> 
> struct S { int i; };
> 
> int i;
> int bar (char *p)
> {
>   char *q = p + 1;
>   i = 1;
>   char *r = (char *)&(((struct S *)&p[i])->i);
>   return q == r;
> }

Rather the following

struct S { int a[4]; };

int i;
int bar (struct S *p)
{
  char *q = (char *)p + 4;
  i = 1;
  int *r = &((struct S *)p)->a[i];
  return q == (char *)r;
}

> the main issue here is that this is vn_reference vs. vn_nary handling and
> this
> transitions from vn_reference to possibly vn_nary with valueization.  For VN
> &MEM[p + 1] was more canonical and we could go back to this when seeing
> pointer-plus -- at least when lookup & simplification does not produce a
> redundancy.
> 
> Handling this in VN only and only when inlining is complete might also avoid
> regressing the testcase again.

The adjusted testcase is folded in forwprop after inlining which handles
p+4 == &p->a[1]

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-01-26 13:48 ` rguenth at gcc dot gnu.org
@ 2022-01-26 14:39 ` rguenth at gcc dot gnu.org
  2022-03-23 12:32 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-26 14:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Created attachment 52293
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52293&action=edit
untested patch

Like this - it unfortunately regresses the diagnostic case in PR99673 again but
should leave early __builtin_object_size untouched.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-01-26 14:39 ` rguenth at gcc dot gnu.org
@ 2022-03-23 12:32 ` rguenth at gcc dot gnu.org
  2022-05-05 12:41 ` [Bug tree-optimization/104162] [12/13 " cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-03-23 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.0                        |13.0
           Priority|P3                          |P2

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

* [Bug tree-optimization/104162] [12/13 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-03-23 12:32 ` rguenth at gcc dot gnu.org
@ 2022-05-05 12:41 ` cvs-commit at gcc dot gnu.org
  2022-12-12 13:32 ` [Bug tree-optimization/104162] [12 " marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-05 12:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:ee1cb43bc76de800efa0ade687b0cd28e62a5f82

commit r13-137-gee1cb43bc76de800efa0ade687b0cd28e62a5f82
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Jan 26 15:34:54 2022 +0100

    tree-optimization/104162 - CSE of &MEM[ptr].a[i] and ptr + CST

    This adds the capability to value-numbering of treating complex
    address expressions where the offset becomes invariant as equal
    to a POINTER_PLUS_EXPR.  This restores CSE that is now prevented
    by early lowering of &MEM[ptr + CST] to a POINTER_PLUS_EXPR.

    Unfortunately this regresses gcc.dg/asan/pr99673.c again, so
    the testcase is adjusted accordingly.

    2022-01-26  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/104162
            * tree-ssa-sccvn.cc (vn_reference_lookup): Handle
            &MEM[_1 + 5].a[i] like a POINTER_PLUS_EXPR if the offset
            becomes invariant.
            (vn_reference_insert): Likewise.

            * gcc.dg/tree-ssa/ssa-fre-99.c: New testcase.
            * gcc.dg/asan/pr99673.c: Adjust.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-05-05 12:41 ` [Bug tree-optimization/104162] [12/13 " cvs-commit at gcc dot gnu.org
@ 2022-12-12 13:32 ` marxin at gcc dot gnu.org
  2023-04-26  6:55 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-12 13:32 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alastair.j.irving at gmail dot com

--- Comment #8 from Martin Liška <marxin at gcc dot gnu.org> ---
*** Bug 108074 has been marked as a duplicate of this bug. ***

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2022-12-12 13:32 ` [Bug tree-optimization/104162] [12 " marxin at gcc dot gnu.org
@ 2023-04-26  6:55 ` rguenth at gcc dot gnu.org
  2023-07-27  9:22 ` rguenth at gcc dot gnu.org
  2024-05-21  9:11 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-26  6:55 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.0                        |13.2

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.1 is being released, retargeting bugs to GCC 13.2.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2023-04-26  6:55 ` rguenth at gcc dot gnu.org
@ 2023-07-27  9:22 ` rguenth at gcc dot gnu.org
  2024-05-21  9:11 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27  9:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.2                        |13.3

--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.

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

* [Bug tree-optimization/104162] [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST]
  2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2023-07-27  9:22 ` rguenth at gcc dot gnu.org
@ 2024-05-21  9:11 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21  9:11 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|13.3                        |13.4

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.

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

end of thread, other threads:[~2024-05-21  9:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-21 13:01 [Bug tree-optimization/104162] New: [12 Regression] Missed CSE after lowering of &MEM[ptr_1 + CST] rguenth at gcc dot gnu.org
2022-01-21 13:01 ` [Bug tree-optimization/104162] " rguenth at gcc dot gnu.org
2022-01-21 13:13 ` rguenth at gcc dot gnu.org
2022-01-21 16:10 ` pinskia at gcc dot gnu.org
2022-01-24  9:50 ` rguenth at gcc dot gnu.org
2022-01-26 13:48 ` rguenth at gcc dot gnu.org
2022-01-26 14:39 ` rguenth at gcc dot gnu.org
2022-03-23 12:32 ` rguenth at gcc dot gnu.org
2022-05-05 12:41 ` [Bug tree-optimization/104162] [12/13 " cvs-commit at gcc dot gnu.org
2022-12-12 13:32 ` [Bug tree-optimization/104162] [12 " marxin at gcc dot gnu.org
2023-04-26  6:55 ` rguenth at gcc dot gnu.org
2023-07-27  9:22 ` rguenth at gcc dot gnu.org
2024-05-21  9:11 ` jakub 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).