public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114711] New: Missed optimization: fold load of global constant array if there is obivous pattern
@ 2024-04-13 17:42 xxs_chy at outlook dot com
  2024-04-13 17:48 ` [Bug tree-optimization/114711] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: xxs_chy at outlook dot com @ 2024-04-13 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114711
           Summary: Missed optimization: fold load of global constant
                    array if there is obivous pattern
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Godbolt link: https://godbolt.org/z/MMxoGaj9T

```
static char* const names[3] = {"abc", "cdf", "dsadsa"};
char** const id2name[3] = {names, names + 1, names + 2};

void* src(size_t idx){
    return id2name[idx];
}

```

can be folded to:

```
static char* const names[3] = {"abc", "cdf", "dsadsa"};
void* tgt(size_t idx){
    return names + idx;
}
```

This is a real pattern from openssl.

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

* [Bug tree-optimization/114711] Missed optimization: fold load of global constant array if there is obivous pattern
  2024-04-13 17:42 [Bug tree-optimization/114711] New: Missed optimization: fold load of global constant array if there is obivous pattern xxs_chy at outlook dot com
@ 2024-04-13 17:48 ` pinskia at gcc dot gnu.org
  2024-04-13 17:50 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-13 17:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note the openssl code issue was reported in pr 114682

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

* [Bug tree-optimization/114711] Missed optimization: fold load of global constant array if there is obivous pattern
  2024-04-13 17:42 [Bug tree-optimization/114711] New: Missed optimization: fold load of global constant array if there is obivous pattern xxs_chy at outlook dot com
  2024-04-13 17:48 ` [Bug tree-optimization/114711] " pinskia at gcc dot gnu.org
@ 2024-04-13 17:50 ` pinskia at gcc dot gnu.org
  2024-04-13 17:57 ` xxs_chy at outlook dot com
  2024-04-15  8:15 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-13 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
           Keywords|                            |missed-optimization
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-13
           Severity|normal                      |enhancement

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In the openssl code, it is a loop which can be unrolled and gcc does and then
is able to handle the load for string just fine but not the resulting ID. See
the linked issue for that.


But confirmed on this one but it is definitely harder.

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

* [Bug tree-optimization/114711] Missed optimization: fold load of global constant array if there is obivous pattern
  2024-04-13 17:42 [Bug tree-optimization/114711] New: Missed optimization: fold load of global constant array if there is obivous pattern xxs_chy at outlook dot com
  2024-04-13 17:48 ` [Bug tree-optimization/114711] " pinskia at gcc dot gnu.org
  2024-04-13 17:50 ` pinskia at gcc dot gnu.org
@ 2024-04-13 17:57 ` xxs_chy at outlook dot com
  2024-04-15  8:15 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: xxs_chy at outlook dot com @ 2024-04-13 17:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from XChy <xxs_chy at outlook dot com> ---
(In reply to Andrew Pinski from comment #1)
> Note the openssl code issue was reported in pr 114682

Oh, thanks for transferring this LLVM issue! And because I'm recently trying to
transfer some of my LLVM issues to GCC and do some statistic work, let me know
if you have transferred some of them.

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

* [Bug tree-optimization/114711] Missed optimization: fold load of global constant array if there is obivous pattern
  2024-04-13 17:42 [Bug tree-optimization/114711] New: Missed optimization: fold load of global constant array if there is obivous pattern xxs_chy at outlook dot com
                   ` (2 preceding siblings ...)
  2024-04-13 17:57 ` xxs_chy at outlook dot com
@ 2024-04-15  8:15 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-15  8:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
This one requires "symbolicizing" an initializer.  That might for example also
help implementing a non-constant initializer with a loop, reducing .data and
possibly relocations.  It might also help reducing compile-time memory usage
when we can have a more compact representation of a CONSTRUCTOR and its
elements.

It feels somewhat similar to what we do in switch-conversion, so maybe some
common infrastructure could be built.

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

end of thread, other threads:[~2024-04-15  8:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-13 17:42 [Bug tree-optimization/114711] New: Missed optimization: fold load of global constant array if there is obivous pattern xxs_chy at outlook dot com
2024-04-13 17:48 ` [Bug tree-optimization/114711] " pinskia at gcc dot gnu.org
2024-04-13 17:50 ` pinskia at gcc dot gnu.org
2024-04-13 17:57 ` xxs_chy at outlook dot com
2024-04-15  8: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).