public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
@ 2023-12-17  9:36 gjl at gcc dot gnu.org
  2023-12-17  9:39 ` [Bug tree-optimization/113049] " gjl at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-12-17  9:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113049
           Summary: Compiles to strlen even with -fno-builtin-strlen
                    -fno-optimize-strlen
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

Compile with -S -Os -fno-builtin-strlen -fno-optimize-strlen

typedef __SIZE_TYPE__ size_t;

size_t strlen (const char *text)
{
  size_t len = 0;

  while (*text)
  {
    text++;
    len++;
  }
  return len;

}

Generated code:

strlen:
        b       strlen


Using built-in specs.
COLLECT_GCC=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc
Target: arm-unknown-linux-gnueabihf
Configured with: /opt/.build/arm-unknown-linux-gnueabihf/src/gcc/configure
--build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu
--target=arm-unknown-linux-gnueabihf
--prefix=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabihf
--exec_prefix=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabihf
--with-sysroot=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot
--enable-languages=c,c++,fortran,d,objc,obj-c++,go --with-arch=armv7-a
--with-fpu=neon --with-float=hard --enable-__cxa_atexit --disable-libmudflap
--enable-libgomp --enable-libssp --enable-libquadmath
--enable-libquadmath-support --enable-libsanitizer --disable-libmpx
--with-gmp=/opt/.build/arm-unknown-linux-gnueabihf/buildtools
--with-mpfr=/opt/.build/arm-unknown-linux-gnueabihf/buildtools
--with-mpc=/opt/.build/arm-unknown-linux-gnueabihf/buildtools
--with-isl=/opt/.build/arm-unknown-linux-gnueabihf/buildtools --enable-lto
--enable-threads=posix --enable-target-optspace --disable-plugin --disable-nls
--enable-tls --disable-multilib
--with-local-prefix=/opt/compiler-explorer/arm/gcc-12.2.0/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot
--enable-long-long --with-mode=thumb
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.2.0 (GCC) 

https://godbolt.org/z/En3j6Gvda

Maybe this is same / similar to PR102725.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
@ 2023-12-17  9:39 ` gjl at gcc dot gnu.org
  2023-12-17 10:05 ` mikpelinux at gmail dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-12-17  9:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
-fno-builtin works, but that seems too much. -fno-builtin-strlen should switch
it off IMO.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
  2023-12-17  9:39 ` [Bug tree-optimization/113049] " gjl at gcc dot gnu.org
@ 2023-12-17 10:05 ` mikpelinux at gmail dot com
  2023-12-17 14:24 ` gjl at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mikpelinux at gmail dot com @ 2023-12-17 10:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Mikael Pettersson <mikpelinux at gmail dot com> ---
Does -fno-tree-loop-distribute-patterns work? That's been the go-to for
disabling similar loop-to-call transformations people have been objecting to.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
  2023-12-17  9:39 ` [Bug tree-optimization/113049] " gjl at gcc dot gnu.org
  2023-12-17 10:05 ` mikpelinux at gmail dot com
@ 2023-12-17 14:24 ` gjl at gcc dot gnu.org
  2023-12-17 15:10 ` schwab@linux-m68k.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-12-17 14:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Mikael Pettersson from comment #2)
> Does -fno-tree-loop-distribute-patterns work? That's been the go-to for
> disabling similar loop-to-call transformations people have been objecting to.

It works. But even if it does, that's not intuitive, and -fno-builtin-strlen
should work no matter what.

And also, when a function's assembly name is "funcxyz", then the compiler
should never issue a concocted call to "funcxyz", because the assumptions of
the compiler of what "funcxyz" is doing is obviously wrong.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-12-17 14:24 ` gjl at gcc dot gnu.org
@ 2023-12-17 15:10 ` schwab@linux-m68k.org
  2023-12-17 15:33 ` gjl at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2023-12-17 15:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andreas Schwab <schwab@linux-m68k.org> ---
-fno-builtin-strlen has a different purpose.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-12-17 15:10 ` schwab@linux-m68k.org
@ 2023-12-17 15:33 ` gjl at gcc dot gnu.org
  2023-12-17 16:47 ` schwab@linux-m68k.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-12-17 15:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andreas Schwab from comment #4)
> -fno-builtin-strlen has a different purpose.

So then -fno-builtin should also not work? GCC documentation of -fno-builtin is
the same like for -fno-builtin-function.

At least there should be an option to disable this, e.g. you need it when
building libgcc / libc anyway, you you get silly non-functional libs.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-12-17 15:33 ` gjl at gcc dot gnu.org
@ 2023-12-17 16:47 ` schwab@linux-m68k.org
  2023-12-17 17:10 ` gjl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: schwab@linux-m68k.org @ 2023-12-17 16:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Andreas Schwab <schwab@linux-m68k.org> ---
That's what -fno-tree-loop-distribute-patterns is for.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-12-17 16:47 ` schwab@linux-m68k.org
@ 2023-12-17 17:10 ` gjl at gcc dot gnu.org
  2023-12-17 17:28 ` harald at gigawatt dot nl
  2023-12-17 17:58 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: gjl at gcc dot gnu.org @ 2023-12-17 17:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
(In reply to Andreas Schwab from comment #6)
> That's what -fno-tree-loop-distribute-patterns is for.

So you know the GCC sources and can draw that conclusion.

The documentation of -ftree-loop-distribute-patterns does not relate in any way
to that.  It's impossible to find this option from a problem description.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-12-17 17:10 ` gjl at gcc dot gnu.org
@ 2023-12-17 17:28 ` harald at gigawatt dot nl
  2023-12-17 17:58 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: harald at gigawatt dot nl @ 2023-12-17 17:28 UTC (permalink / raw)
  To: gcc-bugs

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

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #8 from Harald van Dijk <harald at gigawatt dot nl> ---
(In reply to Georg-Johann Lay from comment #5)
> So then -fno-builtin should also not work? GCC documentation of -fno-builtin
> is the same like for -fno-builtin-function.

-fno-builtin implies -fno-tree-loop-distribute-patterns
(https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=b15458becf4086c463cba0c42db1d8780351201b),
-fno-builtin-strlen does not, but I think you are right that that does not
match the documentation.

(In reply to Georg-Johann Lay from comment #7)
> The documentation of -ftree-loop-distribute-patterns does not relate in any
> way to that.  It's impossible to find this option from a problem description.

-ffreestanding also implies -fno-tree-loop-distribute-patterns, and that option
is documented in a way that would help here. Unless -ffreestanding is used, GCC
assumes the presence of a conforming standard library. It may expand calls to
library functions based on knowledge of what these functions do, and it may
replace code by calls to library functions as well for the same reason.

-fno-builtin and -fno-builtin-(function) are both documented as stopping the
former, but not documented as stopping the latter. The fact that one does, but
not both, is surprising.

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

* [Bug tree-optimization/113049] Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen
  2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2023-12-17 17:28 ` harald at gigawatt dot nl
@ 2023-12-17 17:58 ` pinskia at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-17 17:58 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
dup

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

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

end of thread, other threads:[~2023-12-17 17:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-17  9:36 [Bug tree-optimization/113049] New: Compiles to strlen even with -fno-builtin-strlen -fno-optimize-strlen gjl at gcc dot gnu.org
2023-12-17  9:39 ` [Bug tree-optimization/113049] " gjl at gcc dot gnu.org
2023-12-17 10:05 ` mikpelinux at gmail dot com
2023-12-17 14:24 ` gjl at gcc dot gnu.org
2023-12-17 15:10 ` schwab@linux-m68k.org
2023-12-17 15:33 ` gjl at gcc dot gnu.org
2023-12-17 16:47 ` schwab@linux-m68k.org
2023-12-17 17:10 ` gjl at gcc dot gnu.org
2023-12-17 17:28 ` harald at gigawatt dot nl
2023-12-17 17:58 ` 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).