public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106900] New: Regression after memchr optimization
@ 2022-09-10  5:36 jbglaw@lug-owl.de
  2022-09-10  5:47 ` [Bug tree-optimization/106900] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jbglaw@lug-owl.de @ 2022-09-10  5:36 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106900
           Summary: Regression after memchr optimization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jbglaw@lug-owl.de
  Target Milestone: ---

Hi!

The optimization prepared in PR103798 ("memchr with a (small) constant string
should be expanded inline", c6cf555a88f8ffb8ec85c2b94fe656ab217260ea) caused a
regression for avr-elf, pru-elf and rl78-elf:

.../gcc/configure --prefix=... --enable-werror-always --enable-languages=all
--disable-gcov --disable-shared --disable-threads --target=pru-elf 
--without-headers                                                               
[...]                                                                           
make V=1 all-gcc                                                                
[...]                                                                           
/usr/lib/gcc-snapshot/bin/g++  -fno-PIE -c   -g -O2   -DIN_GCC 
-DCROSS_DIRECTORY_STRUCTURE   -fno-exceptions -fno-rtti
-fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -W
cast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic
-Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -fno-common
 -DHAVE_CONFIG_H -I. -I. -I../../gcc/gcc -I../../gcc/gcc/.
-I../../gcc/gcc/../include -I../../gcc/gcc/../libcpp/include
-I../../gcc/gcc/../libcody  -I../../gcc/gcc/../libdecnumber
-I../../gcc/gcc/../libdecnumber/dpd -I../libdecnumber
-I../../gcc/gcc/../libbacktrace   -o tree-ssa-forwprop.o -MT
tree-ssa-forwprop.o -MMD -MP -MF ./.deps/tree-ssa-forwprop.TPo
../../gcc/gcc/tree-ssa-forwprop.cc
../../gcc/gcc/tree-ssa-forwprop.cc: In function 'bool
simplify_builtin_call(gimple_stmt_iterator*, tree)':
../../gcc/gcc/tree-ssa-forwprop.cc:1258:42: error: array subscript 1 is outside
array bounds of 'tree_node* [1]' [-Werror=array-bounds]
 1258 |             op[i - 1] = fold_convert_loc (loc, boolean_type_node,
      |                         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
 1259 |                                           fold_build2_loc (loc,
      |                                           ~~~~~~~~~~~~~~~~~~~~~
 1260 |                                                           
BIT_IOR_EXPR,
      |                                                           
~~~~~~~~~~~~~
 1261 |                                                           
boolean_type_node,
      |                                                           
~~~~~~~~~~~~~~~~~~
 1262 |                                                            op[i - 1],
      |                                                            ~~~~~~~~~~
 1263 |                                                            op[i]));
      |                                                            ~~~~~~~
In file included from ../../gcc/gcc/system.h:707,
                 from ../../gcc/gcc/tree-ssa-forwprop.cc:21:
../../gcc/gcc/../include/libiberty.h:733:36: note: at offset 8 into object of
size [0, 8] allocated by '__builtin_alloca'
  733 | # define alloca(x) __builtin_alloca(x)
      |                    ~~~~~~~~~~~~~~~~^~~
../../gcc/gcc/../include/libiberty.h:365:40: note: in expansion of macro
'alloca'
  365 | #define XALLOCAVEC(T, N)        ((T *) alloca (sizeof (T) * (N)))
      |                                        ^~~~~~
../../gcc/gcc/tree-ssa-forwprop.cc:1250:22: note: in expansion of macro
'XALLOCAVEC'
 1250 |           tree *op = XALLOCAVEC (tree, isize);
      |                      ^~~~~~~~~~
cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:1146: tree-ssa-forwprop.o] Error 1


(Last confirmed at c2c3e4f6698925c8c969d8525677fbfe98f78909.)

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
@ 2022-09-10  5:47 ` pinskia at gcc dot gnu.org
  2022-09-10  5:48 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-10  5:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Looks like gcc can't figure out that isize can't be 0 even if there was a check
for integer_zerop (size) before hand.
There must be a way to add an assert there to allow gcc to figure that out.

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
  2022-09-10  5:47 ` [Bug tree-optimization/106900] " pinskia at gcc dot gnu.org
@ 2022-09-10  5:48 ` pinskia at gcc dot gnu.org
  2023-02-25 19:33 ` jbglaw@lug-owl.de
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-09-10  5:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Obviously this only happens because you use --enable-werror-always

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
  2022-09-10  5:47 ` [Bug tree-optimization/106900] " pinskia at gcc dot gnu.org
  2022-09-10  5:48 ` pinskia at gcc dot gnu.org
@ 2023-02-25 19:33 ` jbglaw@lug-owl.de
  2023-05-16 21:33 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jbglaw@lug-owl.de @ 2023-02-25 19:33 UTC (permalink / raw)
  To: gcc-bugs

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

Jan-Benedict Glaw <jbglaw@lug-owl.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |avr-elf, pru-elf, rl78-elf

--- Comment #3 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
Sure, just a warning, but still there (as of
31303c9b5bab200754cdb7ef8cd91ae4918f3018) and affecting three targets. Maybe we
get that understood/fixed?

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
                   ` (2 preceding siblings ...)
  2023-02-25 19:33 ` jbglaw@lug-owl.de
@ 2023-05-16 21:33 ` pinskia at gcc dot gnu.org
  2023-05-17  4:24 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-16 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-05-16

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I am just going to test:
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 06f19868ade..0326e6733e8 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -1231,14 +1231,14 @@ simplify_builtin_call (gimple_stmt_iterator *gsi_p,
tree callee2)
          tree size = gimple_call_arg (stmt2, 2);
          /* Size must be a constant which is <= UNITS_PER_WORD and
             <= the string length.  */
-         if (TREE_CODE (size) != INTEGER_CST || integer_zerop (size))
+         if (TREE_CODE (size) != INTEGER_CST)
            break;

          if (!tree_fits_uhwi_p (size))
            break;

          unsigned HOST_WIDE_INT sz = tree_to_uhwi (size);
-         if (sz > UNITS_PER_WORD || sz >= slen)
+         if (sz == 0 || sz > UNITS_PER_WORD || sz >= slen)
            break;

          tree ch = gimple_call_arg (stmt2, 1);


This does not change the behavior of the code at all, just makes it obvious sz
cannot be 0 and therefore isize won't be 0 either.

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
                   ` (3 preceding siblings ...)
  2023-05-16 21:33 ` pinskia at gcc dot gnu.org
@ 2023-05-17  4:24 ` pinskia at gcc dot gnu.org
  2023-05-17 15:03 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-17  4:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                URL|                            |https://gcc.gnu.org/piperma
                   |                            |il/gcc-patches/2023-May/618
                   |                            |762.html

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-May/618762.html

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
                   ` (4 preceding siblings ...)
  2023-05-17  4:24 ` pinskia at gcc dot gnu.org
@ 2023-05-17 15:03 ` cvs-commit at gcc dot gnu.org
  2023-05-17 15:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-17 15:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

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

commit r14-937-gf65af1eeef670f2c249b1896726ef57bbf65fe2f
Author: Andrew Pinski <apinski@marvell.com>
Date:   Tue May 16 14:34:05 2023 -0700

    Fix PR 106900: array-bounds warning inside simplify_builtin_call

    The problem here is that VRP cannot figure out isize could not be 0
    due to using integer_zerop. This patch removes the use of integer_zerop
    and instead checks for 0 directly after converting the tree to
    an unsigned HOST_WIDE_INT. This allows VRP to figure out isize is not 0
    and `isize - 1` will always be >= 0.

    This patch is just to avoid the warning that GCC could produce sometimes
    and does not change any code generation or even VRP.

    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

    gcc/ChangeLog:

            * tree-ssa-forwprop.cc (simplify_builtin_call): Check
            against 0 instead of calling integer_zerop.

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
                   ` (5 preceding siblings ...)
  2023-05-17 15:03 ` cvs-commit at gcc dot gnu.org
@ 2023-05-17 15:05 ` pinskia at gcc dot gnu.org
  2023-05-17 18:40 ` jbglaw@lug-owl.de
  2023-05-18 15:47 ` jbglaw@lug-owl.de
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-17 15:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |14.0
             Status|ASSIGNED                    |RESOLVED

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed on the trunk; not really worth backporting since it is only an issue with
--enable-werror-always which almost nobody uses.

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
                   ` (6 preceding siblings ...)
  2023-05-17 15:05 ` pinskia at gcc dot gnu.org
@ 2023-05-17 18:40 ` jbglaw@lug-owl.de
  2023-05-18 15:47 ` jbglaw@lug-owl.de
  8 siblings, 0 replies; 10+ messages in thread
From: jbglaw@lug-owl.de @ 2023-05-17 18:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
Thanks a lot!  I scheduled builds for the three affected targets (from my
target list.) The box is quite loaded right now (and a few jobs a before those
three), so I guess it'll take a few hours.

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

* [Bug tree-optimization/106900] Regression after memchr optimization
  2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
                   ` (7 preceding siblings ...)
  2023-05-17 18:40 ` jbglaw@lug-owl.de
@ 2023-05-18 15:47 ` jbglaw@lug-owl.de
  8 siblings, 0 replies; 10+ messages in thread
From: jbglaw@lug-owl.de @ 2023-05-18 15:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jan-Benedict Glaw <jbglaw@lug-owl.de> ---
All three target configurations reported a successful build. Thanks!

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

end of thread, other threads:[~2023-05-18 15:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-10  5:36 [Bug tree-optimization/106900] New: Regression after memchr optimization jbglaw@lug-owl.de
2022-09-10  5:47 ` [Bug tree-optimization/106900] " pinskia at gcc dot gnu.org
2022-09-10  5:48 ` pinskia at gcc dot gnu.org
2023-02-25 19:33 ` jbglaw@lug-owl.de
2023-05-16 21:33 ` pinskia at gcc dot gnu.org
2023-05-17  4:24 ` pinskia at gcc dot gnu.org
2023-05-17 15:03 ` cvs-commit at gcc dot gnu.org
2023-05-17 15:05 ` pinskia at gcc dot gnu.org
2023-05-17 18:40 ` jbglaw@lug-owl.de
2023-05-18 15:47 ` jbglaw@lug-owl.de

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).