public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8
@ 2023-07-19  9:03 shaohua.li at inf dot ethz.ch
  2023-07-19  9:08 ` [Bug c/110738] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-07-19  9:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110738
           Summary: GCC trunk failed to do some optimizations since GCC-8
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: shaohua.li at inf dot ethz.ch
  Target Milestone: ---

For the following test case, gcc trunk at -O3 emits a relatively large assembly
code since GCC-8. Clang can remove all the code.

Compiler explorer: https://godbolt.org/z/hzf8Pr484

The test case is adapted from an official GCC test case:
https://github.com/gcc-mirror/gcc/blob/ae862e0e47cb2d62d7c624ab999a3bd8bd2914ef/gcc/testsuite/gcc.dg/strncmp-3.c

I only changed `int neg=0` to `int neg=1`. 

$ gcc-tk -O3 -S -o trunk.s a.c
$ gcc-7.4 -O3 -S -o old.s a.c
$ wc trunk.s old.s
 217  654 5999 trunk.s
  11   19  175 old.s
 228  673 6174 total
$
$ cat a.c
#define AB_D "ab\0d"
#define ABCDEF_H "abcdef\0h"
#define ABCDEFGHIJKLMN_P "abcdefghijklmn\0p"

char ab_d[] = AB_D;
char abcdef_h[] = ABCDEF_H;

extern int strncmp (const char*, const char*, __SIZE_TYPE__);

__attribute__((noipa)) void sink (const void *p, ...) { (void)&p; }

#define strncmp(a, b, n) (sink (a, b), strncmp (a, b, n))

int main (void)
{
  int zero = 0;

  zero += strncmp (ab_d, AB_D,1);
  zero += strncmp (ab_d, AB_D,2);
  zero += strncmp (ab_d, AB_D,3);
  zero += strncmp (ab_d, AB_D,4);
  zero += strncmp (ab_d, AB_D,5);

  zero += strncmp (ab_d, ABCDEF_H,1);
  zero += strncmp (ab_d, ABCDEF_H,2);

  zero += strncmp (abcdef_h, AB_D,2);

  zero += strncmp (abcdef_h, ABCDEF_H,2);
  zero += strncmp (abcdef_h, ABCDEF_H,3);
  zero += strncmp (abcdef_h, ABCDEF_H,4);
  zero += strncmp (abcdef_h, ABCDEF_H,5);
  zero += strncmp (abcdef_h, ABCDEF_H,6);
  zero += strncmp (abcdef_h, ABCDEF_H,7);
  zero += strncmp (abcdef_h, ABCDEF_H,8);
  zero += strncmp (abcdef_h, ABCDEF_H,9);
  if (zero != 0)
    __builtin_abort ();
  int neg = 1;
  neg -= strncmp (ab_d, ABCDEF_H,3) <0;
  neg -= strncmp (ab_d, ABCDEF_H,4) <0;
  neg -= strncmp (ab_d, ABCDEF_H,5) <0;
  neg -= strncmp (ab_d, ABCDEF_H,6) <0;
  neg -= strncmp (ab_d, ABCDEF_H,7) <0;
  neg -= strncmp (ab_d, ABCDEF_H,8) <0;
  neg -= strncmp (ab_d, ABCDEF_H,9) <0;
  if (neg !=-7){
    __builtin_abort ();
  }
}
$
$ gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-ec842611618c9f8a50f3326d42c51961de8b28a5/libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-ec842611618c9f8a50f3326d42c51961de8b28a5
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230719 (experimental) (GCC) 
$

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

* [Bug c/110738] GCC trunk failed to do some optimizations since GCC-8
  2023-07-19  9:03 [Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8 shaohua.li at inf dot ethz.ch
@ 2023-07-19  9:08 ` pinskia at gcc dot gnu.org
  2023-07-19  9:10 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-19  9:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>Clang can remove all the code.

Clang does not implement the noipa attribute.

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

* [Bug c/110738] GCC trunk failed to do some optimizations since GCC-8
  2023-07-19  9:03 [Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8 shaohua.li at inf dot ethz.ch
  2023-07-19  9:08 ` [Bug c/110738] " pinskia at gcc dot gnu.org
@ 2023-07-19  9:10 ` pinskia at gcc dot gnu.org
  2023-07-19  9:16 ` shaohua.li at inf dot ethz.ch
  2023-07-19 11:18 ` xry111 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-19  9:10 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The noipa attribute was only added in gcc 8.

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

* [Bug c/110738] GCC trunk failed to do some optimizations since GCC-8
  2023-07-19  9:03 [Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8 shaohua.li at inf dot ethz.ch
  2023-07-19  9:08 ` [Bug c/110738] " pinskia at gcc dot gnu.org
  2023-07-19  9:10 ` pinskia at gcc dot gnu.org
@ 2023-07-19  9:16 ` shaohua.li at inf dot ethz.ch
  2023-07-19 11:18 ` xry111 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-07-19  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Shaohua Li <shaohua.li at inf dot ethz.ch> ---
Would this test case be interesting? If no, I won't report other similar
issues.

https://godbolt.org/z/9xr1rv37s

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

* [Bug c/110738] GCC trunk failed to do some optimizations since GCC-8
  2023-07-19  9:03 [Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8 shaohua.li at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-07-19  9:16 ` shaohua.li at inf dot ethz.ch
@ 2023-07-19 11:18 ` xry111 at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2023-07-19 11:18 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

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

--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Shaohua Li from comment #3)
> Would this test case be interesting? If no, I won't report other similar
> issues.
> 
> https://godbolt.org/z/9xr1rv37s

But it works at -O2.  So I suppose this is just an effect of disabling some
optimizations in -O1, and I guess the change is likely deliberate.

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

end of thread, other threads:[~2023-07-19 11:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19  9:03 [Bug c/110738] New: GCC trunk failed to do some optimizations since GCC-8 shaohua.li at inf dot ethz.ch
2023-07-19  9:08 ` [Bug c/110738] " pinskia at gcc dot gnu.org
2023-07-19  9:10 ` pinskia at gcc dot gnu.org
2023-07-19  9:16 ` shaohua.li at inf dot ethz.ch
2023-07-19 11:18 ` xry111 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).