public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/112525] New: fail to eliminate unused store
@ 2023-11-14  6:40 guojiufu at gcc dot gnu.org
  2023-11-14  6:48 ` [Bug rtl-optimization/112525] " guojiufu at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: guojiufu at gcc dot gnu.org @ 2023-11-14  6:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112525
           Summary: fail to eliminate unused store
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: guojiufu at gcc dot gnu.org
  Target Milestone: ---

For below code:
```
typedef struct teststruct
{
  double d;
  int arr[15]; /* for ppc64le example foo1, 14: foo is just blr. 15: foo has 8
'std's */
} teststruct;

int
foo (int a, teststruct p)
{
  if (a > 0)
    return 1;
  return 2;
}

void
foo1 (teststruct p)
{
}
```

Some instructions are generated to store "p" to stack (stored to areas of arg
pointer/virtual_incoming_pointer).
But those stores are not eliminated.

For example, on ppc64le, below code is generated:
```
foo1:
.LFB1:
        .cfi_startproc
        std 3,32(1)
        std 4,40(1)
        std 5,48(1)
        std 6,56(1)
        std 7,64(1)
        std 8,72(1)
        std 9,80(1)
        std 10,88(1)
        blr
```
Those 'std's are dead actually.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
@ 2023-11-14  6:48 ` guojiufu at gcc dot gnu.org
  2023-11-14  6:49 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: guojiufu at gcc dot gnu.org @ 2023-11-14  6:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jiu Fu Guo <guojiufu at gcc dot gnu.org> ---
(In reply to Jiu Fu Guo from comment #0)
> For below code:
> ```
> typedef struct teststruct
> {
>   double d;
>   int arr[15]; /* for ppc64le example foo1, 14: foo is just blr. 15: foo has
> 8 'std's */
> } teststruct;

Here, if the code is "int arr[14];", the struct is just passed via registers
(in foo function); and in the expander pass, they are stored to frame area. 
If the code is "int arr[15];",  the struct is passed through registers
partially, and the other partial is through memory; and in the expander pass,
they are stored to the area which is pointed via arg pointer.

In DSE pass, the 'dead' stores to 'frame' can be eliminated.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
  2023-11-14  6:48 ` [Bug rtl-optimization/112525] " guojiufu at gcc dot gnu.org
@ 2023-11-14  6:49 ` pinskia at gcc dot gnu.org
  2023-11-14  7:01 ` guojiufu at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-14  6:49 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=30271,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=39102

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
And more

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
  2023-11-14  6:48 ` [Bug rtl-optimization/112525] " guojiufu at gcc dot gnu.org
  2023-11-14  6:49 ` pinskia at gcc dot gnu.org
@ 2023-11-14  7:01 ` guojiufu at gcc dot gnu.org
  2023-11-14  7:44 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: guojiufu at gcc dot gnu.org @ 2023-11-14  7:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jiu Fu Guo <guojiufu at gcc dot gnu.org> ---
One possible method is fixing DSE to let is able to remove those 'store's.
(but need to take care of the case that is using 'arg_pointer' to pass
parameters.)


Another method: there is a patch
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/634500.html which
introduces lighter-expander-sra (this patch is only for struct parameter now).
We may enhance this patch to avoid storing the unused parameters.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-11-14  7:01 ` guojiufu at gcc dot gnu.org
@ 2023-11-14  7:44 ` rguenth at gcc dot gnu.org
  2023-11-14  7:45 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-14  7:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-11-14

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I wonder if optimizing for "unused" parameters is worth it (usually IPA SRA
will elide them).  "unused" could be computed by cfgexpand walking the body,
but
we do expect to be able to inspect those parameters with -g, so care has to
be taken that this works at all optimization levels.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-11-14  7:44 ` rguenth at gcc dot gnu.org
@ 2023-11-14  7:45 ` rguenth at gcc dot gnu.org
  2023-11-15  1:49 ` guojiufu at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-11-14  7:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |powerpc64le

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
On x86 calling conventions seem to avoid this issue.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-11-14  7:45 ` rguenth at gcc dot gnu.org
@ 2023-11-15  1:49 ` guojiufu at gcc dot gnu.org
  2023-12-19  5:18 ` cvs-commit at gcc dot gnu.org
  2024-01-04  0:47 ` guojiufu at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: guojiufu at gcc dot gnu.org @ 2023-11-15  1:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jiu Fu Guo <guojiufu at gcc dot gnu.org> ---
(In reply to Jiu Fu Guo from comment #3)
> One possible method is fixing DSE to let is able to remove those 'store's.
> (but need to take care of the case that is using 'arg_pointer' to pass
> parameters.)
> 

Some 'store's to the incoming argument area (arg_pointer_rtx) may not safe to
be removed:
For example: call memset on X86_64 , the insn(s) maybe:
  134: [argp+0x8]=r134:SI
  135: [argp+0x4]=0x1
  136: [argp]=r132:SI
  137: ax:SI=call [`memset'] argc:0xc
      REG_CALL_DECL `memset'
      REG_EH_REGION 0

insn(s) 134/135/136 can not be removed.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-11-15  1:49 ` guojiufu at gcc dot gnu.org
@ 2023-12-19  5:18 ` cvs-commit at gcc dot gnu.org
  2024-01-04  0:47 ` guojiufu at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-19  5:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jiu Fu Guo <guojiufu@gcc.gnu.org>:

https://gcc.gnu.org/g:4759383245ac97a5c83c0272f0a831f2a26ea5c1

commit r14-6674-g4759383245ac97a5c83c0272f0a831f2a26ea5c1
Author: Jiufu Guo <guojiufu@linux.ibm.com>
Date:   Tue Dec 19 13:03:06 2023 +0800

    treat argp-based mem as frame related in dse

    The issue mentioned in PR112525 would be able to be handled by
    updating dse.cc to treat arg_pointer_rtx similarly with frame_pointer_rtx.
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=30271#c10 also mentioned
    this idea.

    And arpg area may be used to pass argument to callee. So, it would
    be needed to check if call insns are using that mem.

            PR rtl-optimization/112525
            PR target/30271

    gcc/ChangeLog:

            * dse.cc (get_group_info): Add arg_pointer_rtx as frame_related.
            (check_mem_read_rtx): Add parameter to indicate if it is checking
mem
            for call insn.
            (scan_insn): Add mem checking on call usage.

    gcc/testsuite/ChangeLog:

            * gcc.target/powerpc/pr112525.c: New test.
            * gcc.target/powerpc/pr30271.c: New test.

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

* [Bug rtl-optimization/112525] fail to eliminate unused store
  2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-12-19  5:18 ` cvs-commit at gcc dot gnu.org
@ 2024-01-04  0:47 ` guojiufu at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: guojiufu at gcc dot gnu.org @ 2024-01-04  0:47 UTC (permalink / raw)
  To: gcc-bugs

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

Jiu Fu Guo <guojiufu at gcc dot gnu.org> changed:

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

--- Comment #8 from Jiu Fu Guo <guojiufu at gcc dot gnu.org> ---
Fix committed.

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

end of thread, other threads:[~2024-01-04  0:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-14  6:40 [Bug rtl-optimization/112525] New: fail to eliminate unused store guojiufu at gcc dot gnu.org
2023-11-14  6:48 ` [Bug rtl-optimization/112525] " guojiufu at gcc dot gnu.org
2023-11-14  6:49 ` pinskia at gcc dot gnu.org
2023-11-14  7:01 ` guojiufu at gcc dot gnu.org
2023-11-14  7:44 ` rguenth at gcc dot gnu.org
2023-11-14  7:45 ` rguenth at gcc dot gnu.org
2023-11-15  1:49 ` guojiufu at gcc dot gnu.org
2023-12-19  5:18 ` cvs-commit at gcc dot gnu.org
2024-01-04  0:47 ` guojiufu 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).