* [Bug tree-optimization/102216] False positive warray-bounds with -O2
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
@ 2021-09-06 10:45 ` pinskia at gcc dot gnu.org
2021-09-06 20:46 ` pinskia at gcc dot gnu.org
` (15 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-06 10:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
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| |2021-09-06
CC| |pinskia at gcc dot gnu.org
Keywords| |diagnostic,
| |missed-optimization
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The problem is dead code:
language_names_p_9 = &MEM <const char *> [(void *)_4 + 24B];
MEM[(const char * *)_4 + 24B] = "";
MEM[(const char * *)_4 + 32B] = "";
MEM[(const char * *)_4 + 40B] = 0B;
_2 = _4 + 40;
D.50907._M_comp = compare_cstrings;
__comp = D.50907;
if (_2 != language_names_p_9)
goto <bb 3>; [53.47%]
else
goto <bb 12>; [46.53%]
<bb 3> [local count: 574129759]:
_15 = _2 - language_names_p_9;
_16 = _15 /[ex] 8;
...
_22 = _2 - language_names_p_9;
if (_22 > 128)
goto <bb 4>; [50.00%]
else
goto <bb 10>; [50.00%]
<bb 4> [local count: 287064879]:
_23 = &MEM <const char *> [(void *)_4 + 152B];
std::__insertion_sort<const char**, __gnu_cxx::__ops::_Iter_comp_iter<bool
(*)(const char*, const char*)> > (language_names_p_9, _23, __comp);
__comp_24 = MEM[(struct _Iter_comp_iter *)&__comp];
goto <bb 9>; [100.00%]
That is _22 (and _15) should be 16.
I just fixed a similar issue today (but the patch did not fix this case).
I will look into fixing this one tomorrow.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] False positive warray-bounds with -O2
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
2021-09-06 10:45 ` [Bug tree-optimization/102216] " pinskia at gcc dot gnu.org
@ 2021-09-06 20:46 ` pinskia at gcc dot gnu.org
2021-09-07 1:32 ` [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds pinskia at gcc dot gnu.org
` (14 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-06 20:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> The problem is dead code:
> language_names_p_9 = &MEM <const char *> [(void *)_4 + 24B];
> MEM[(const char * *)_4 + 24B] = "";
> MEM[(const char * *)_4 + 32B] = "";
> MEM[(const char * *)_4 + 40B] = 0B;
> _2 = _4 + 40;
> D.50907._M_comp = compare_cstrings;
> __comp = D.50907;
> if (_2 != language_names_p_9)
> goto <bb 3>; [53.47%]
> else
> goto <bb 12>; [46.53%]
>
> <bb 3> [local count: 574129759]:
> _15 = _2 - language_names_p_9;
> _16 = _15 /[ex] 8;
>
> ...
> _22 = _2 - language_names_p_9;
I have a (hack) patch which removes the first if statement but still does not
fold _15 and _22.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
2021-09-06 10:45 ` [Bug tree-optimization/102216] " pinskia at gcc dot gnu.org
2021-09-06 20:46 ` pinskia at gcc dot gnu.org
@ 2021-09-07 1:32 ` pinskia at gcc dot gnu.org
2021-09-07 1:47 ` pinskia at gcc dot gnu.org
` (13 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-07 1:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|False positive |[12 Regression] missed
|warray-bounds with -O2 |optimization causing
| |Warray-bounds
Target Milestone|--- |12.0
Known to work| |4.4.7
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a short testcase:
int
add_set_language_command ()
{
const char **language_names;
language_names = new const char *[6];
const char **language_names_p = language_names;
language_names_p++;
language_names_p++;
language_names_p++;
return (language_names_p) - (language_names+3);
}
This should just return 0; Which was able to be done in GCC 4.4.7.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (2 preceding siblings ...)
2021-09-07 1:32 ` [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds pinskia at gcc dot gnu.org
@ 2021-09-07 1:47 ` pinskia at gcc dot gnu.org
2021-09-07 6:31 ` pinskia at gcc dot gnu.org
` (12 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-07 1:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |TREE
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So how 4.4.x got the right answer at the tree level was just by accident
really. VRP used SCEV which basically does a combine. Forwprop never happened
of PointerPlus until 4.6. 4.5 removed the SCEV usage in VRP and removed the
optimization ...
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (3 preceding siblings ...)
2021-09-07 1:47 ` pinskia at gcc dot gnu.org
@ 2021-09-07 6:31 ` pinskia at gcc dot gnu.org
2021-09-07 7:21 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-07 6:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think I have a patch which disables the proping in forwprop that creates the
&MEM stuff (it is done still by forwprop just not in this location and via
match instead). The waring is now gone and the code looks better too.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (4 preceding siblings ...)
2021-09-07 6:31 ` pinskia at gcc dot gnu.org
@ 2021-09-07 7:21 ` pinskia at gcc dot gnu.org
2021-09-07 18:50 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-07 7:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 51420
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51420&action=edit
Patch which I am testing.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (5 preceding siblings ...)
2021-09-07 7:21 ` pinskia at gcc dot gnu.org
@ 2021-09-07 18:50 ` pinskia at gcc dot gnu.org
2021-09-07 21:37 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-07 18:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #6)
> Created attachment 51420 [details]
> Patch which I am testing.
Note I am throwing this patch away and started to rewrite parts of
tree-ssa-forwprop.c instead.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (6 preceding siblings ...)
2021-09-07 18:50 ` pinskia at gcc dot gnu.org
@ 2021-09-07 21:37 ` pinskia at gcc dot gnu.org
2021-09-15 16:40 ` msebor at gcc dot gnu.org
` (8 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-07 21:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #51420|0 |1
is obsolete| |
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 51424
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51424&action=edit
New patch
THis is the new patch which I am testing. It fixes the original issue in
forwprop but does not fix the FIXME of creating extra trees.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (7 preceding siblings ...)
2021-09-07 21:37 ` pinskia at gcc dot gnu.org
@ 2021-09-15 16:40 ` msebor at gcc dot gnu.org
2021-09-15 19:19 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-09-15 16:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Bug 102216 depends on bug 102238, which changed state.
Bug 102238 Summary: alias_offset in gimple-ssa-sprintf.c is broken
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102238
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (8 preceding siblings ...)
2021-09-15 16:40 ` msebor at gcc dot gnu.org
@ 2021-09-15 19:19 ` pinskia at gcc dot gnu.org
2021-10-27 9:28 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-15 19:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Bug 102216 depends on bug 102238, which changed state.
Bug 102238 Summary: alias_offset in gimple-ssa-sprintf.c is broken
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102238
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (9 preceding siblings ...)
2021-09-15 19:19 ` pinskia at gcc dot gnu.org
@ 2021-10-27 9:28 ` pinskia at gcc dot gnu.org
2021-11-23 0:50 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-27 9:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2021-October
| |/582684.html
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch submitted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-October/582684.html
Now that PR 102238 is fixed.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (10 preceding siblings ...)
2021-10-27 9:28 ` pinskia at gcc dot gnu.org
@ 2021-11-23 0:50 ` pinskia at gcc dot gnu.org
2021-11-23 1:31 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 0:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #51424|0 |1
is obsolete| |
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 51850
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51850&action=edit
Updated patch
Updated patch based on the feedback, still need to add back the testcase
though.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (11 preceding siblings ...)
2021-11-23 0:50 ` pinskia at gcc dot gnu.org
@ 2021-11-23 1:31 ` pinskia at gcc dot gnu.org
2021-11-23 5:30 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 1:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #10)
> Created attachment 51850 [details]
> Updated patch
Note this patch is broken but I have the corrected patch which I am testing
now.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (12 preceding siblings ...)
2021-11-23 1:31 ` pinskia at gcc dot gnu.org
@ 2021-11-23 5:30 ` pinskia at gcc dot gnu.org
2021-11-23 8:45 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 5:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL|https://gcc.gnu.org/piperma |https://gcc.gnu.org/piperma
|il/gcc-patches/2021-October |il/gcc-patches/2021-Novembe
|/582684.html |r/585194.html
--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
New patch submitted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/585194.html
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (13 preceding siblings ...)
2021-11-23 5:30 ` pinskia at gcc dot gnu.org
@ 2021-11-23 8:45 ` pinskia at gcc dot gnu.org
2021-11-23 9:57 ` cvs-commit at gcc dot gnu.org
2021-11-23 10:01 ` pinskia at gcc dot gnu.org
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 8:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
--- Comment #13 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 103377 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (14 preceding siblings ...)
2021-11-23 8:45 ` pinskia at gcc dot gnu.org
@ 2021-11-23 9:57 ` cvs-commit at gcc dot gnu.org
2021-11-23 10:01 ` pinskia at gcc dot gnu.org
16 siblings, 0 replies; 18+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-23 9:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
--- Comment #14 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:911b633803dcbb298c98777e29fd260834c0d04a
commit r12-5465-g911b633803dcbb298c98777e29fd260834c0d04a
Author: Andrew Pinski <apinski@marvell.com>
Date: Tue Nov 23 01:08:55 2021 +0000
Canonicalize &MEM[ssa_n, CST] to ssa_n p+ CST in fold_stmt_1
This is a new version of the patch to fix PR 102216.
Instead of doing the canonicalization inside forwprop, Richi
mentioned we should do it inside fold_stmt_1 and that is what
this patch does.
PR tree-optimization/102216
gcc/ChangeLog:
* gimple-fold.c (fold_stmt_1): Add canonicalization
of "&MEM[ssa_n, CST]" to "ssa_n p+ CST", note this
can only be done if !in_place.
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/pr102216-1.C: New test.
* g++.dg/tree-ssa/pr102216-2.C: New test.
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Bug tree-optimization/102216] [12 Regression] missed optimization causing Warray-bounds
2021-09-06 10:14 [Bug tree-optimization/102216] New: False positive warray-bounds with -O2 vries at gcc dot gnu.org
` (15 preceding siblings ...)
2021-11-23 9:57 ` cvs-commit at gcc dot gnu.org
@ 2021-11-23 10:01 ` pinskia at gcc dot gnu.org
16 siblings, 0 replies; 18+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-23 10:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102216
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #15 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 18+ messages in thread