public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108008] New: Compiler mis-optimization with posix_memalign
@ 2022-12-07 14:06 hahnjo at hahnjo dot de
2022-12-07 14:43 ` [Bug c++/108008] " amonakov at gcc dot gnu.org
` (14 more replies)
0 siblings, 15 replies; 16+ messages in thread
From: hahnjo at hahnjo dot de @ 2022-12-07 14:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Bug ID: 108008
Summary: Compiler mis-optimization with posix_memalign
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hahnjo at hahnjo dot de
Target Milestone: ---
Created attachment 54033
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54033&action=edit
init.cpp
Consider the attached example, reduced from some real code, and also available
on Compiler Explorer: https://godbolt.org/z/x4Gsjo7rT
The expectation is that sameZ[i] = true if zPlanes[i] == zPlanes[i + 1] which
should be the case for i = 1. However, when compiling the code with GCC 11.2.0
or 12.2.0 and -std=c++17 -O3, the output is sameZ = 0 for all three iterations
of the second loop. The problem disappears when changing anything in the
slightest manner: compiling with -O2, using -std=gnu++17, using a different
allocation function, commenting out one of the other two statements in the
first loop, using the unconditional assignment to sameZ[i], or removing the
exit(1).
Could this be a bug in the optimizer?
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug c++/108008] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
@ 2022-12-07 14:43 ` amonakov at gcc dot gnu.org
2022-12-07 22:12 ` [Bug tree-optimization/108008] " dhsbz at chaw dot com
` (13 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: amonakov at gcc dot gnu.org @ 2022-12-07 14:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Alexander Monakov <amonakov at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amonakov at gcc dot gnu.org
--- Comment #1 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
-fno-split-loops "cures" it (of course it might just be an enabling transform
for an incorrect optimization later on)
Bisecting trunk for which commit fixes/hides it may be useful.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
2022-12-07 14:43 ` [Bug c++/108008] " amonakov at gcc dot gnu.org
@ 2022-12-07 22:12 ` dhsbz at chaw dot com
2022-12-07 22:24 ` pinskia at gcc dot gnu.org
` (12 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: dhsbz at chaw dot com @ 2022-12-07 22:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
dhsbz at chaw dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |dhsbz at chaw dot com
--- Comment #2 from dhsbz at chaw dot com ---
I tried the example with gcc master, and it seems to behave as expected (i.e.
sameZ=1 for i=1). Tracking back it seems the commit which restored this was:
commit ce92603fbe3b4870e0a38efee1ee766d62942065 (HEAD)
Author: Richard Biener
Date: Mon Jul 18 12:06:00 2022 +0200
Improve common reduction vs builtin code generation in loop distribution
[...]
(using gcc as of the prior commit shows the behavior as in the bug
description). I can't judge if the above commit had fixed an underlying problem
that the example was triggering, or if it changed the behavior in an indirect
way.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
2022-12-07 14:43 ` [Bug c++/108008] " amonakov at gcc dot gnu.org
2022-12-07 22:12 ` [Bug tree-optimization/108008] " dhsbz at chaw dot com
@ 2022-12-07 22:24 ` pinskia at gcc dot gnu.org
2022-12-07 22:37 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07 22:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to dhsbz from comment #2)
> I tried the example with gcc master, and it seems to behave as expected
> (i.e. sameZ=1 for i=1). Tracking back it seems the commit which restored
> this was:
r13-1728-gce92603fbe3b48
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (2 preceding siblings ...)
2022-12-07 22:24 ` pinskia at gcc dot gnu.org
@ 2022-12-07 22:37 ` pinskia at gcc dot gnu.org
2022-12-07 22:48 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07 22:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 54041
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54041&action=edit
Slightly more reduced testcase
Slightly more reduced and self contained testcase.
I was able to remove the exit from Init as it just caused the function not to
be inlined.
There is more to be done to reduce it further though.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (3 preceding siblings ...)
2022-12-07 22:37 ` pinskia at gcc dot gnu.org
@ 2022-12-07 22:48 ` pinskia at gcc dot gnu.org
2022-12-07 22:58 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07 22:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #54041|0 |1
is obsolete| |
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 54042
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54042&action=edit
Removed headers and removed difference from -std=c++17/-std=gnu++17
-std=c++17 was causing posix_memalign not to be known as a allocator and such.
Hide it using the gnu::noipa attribute instead.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (4 preceding siblings ...)
2022-12-07 22:48 ` pinskia at gcc dot gnu.org
@ 2022-12-07 22:58 ` pinskia at gcc dot gnu.org
2022-12-07 23:05 ` [Bug tree-optimization/108008] [12 Regression] " pinskia at gcc dot gnu.org
` (8 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07 22:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #54042|0 |1
is obsolete| |
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 54043
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54043&action=edit
Reduced further but needs -O3 -fno-tree-vectorize to hit the bug
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (5 preceding siblings ...)
2022-12-07 22:58 ` pinskia at gcc dot gnu.org
@ 2022-12-07 23:05 ` pinskia at gcc dot gnu.org
2022-12-07 23:05 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07 23:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-12-07
Summary|Compiler mis-optimization |[12 Regression] Compiler
|with posix_memalign |mis-optimization with
| |posix_memalign
Target Milestone|--- |12.3
Ever confirmed|0 |1
Known to work| |8.1.0
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to dhsbz from comment #2)
> (using gcc as of the prior commit shows the behavior as in the bug
> description). I can't judge if the above commit had fixed an underlying
> problem that the example was triggering, or if it changed the behavior in an
> indirect way.
I think it just changes the IR just ever so slightly which makes the problem go
latent. As shown sometimes adding and removing vectorization.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] Compiler mis-optimization with posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (6 preceding siblings ...)
2022-12-07 23:05 ` [Bug tree-optimization/108008] [12 Regression] " pinskia at gcc dot gnu.org
@ 2022-12-07 23:05 ` pinskia at gcc dot gnu.org
2022-12-08 8:44 ` [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign amonakov at gcc dot gnu.org
` (6 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-12-07 23:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #7)
> (In reply to dhsbz from comment #2)
> > (using gcc as of the prior commit shows the behavior as in the bug
> > description). I can't judge if the above commit had fixed an underlying
> > problem that the example was triggering, or if it changed the behavior in an
> > indirect way.
>
> I think it just changes the IR just ever so slightly which makes the problem
> go latent. As shown sometimes adding and removing vectorization.
Even my example does not show the issue with GCC 11 but does show it with GCC
12.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (7 preceding siblings ...)
2022-12-07 23:05 ` pinskia at gcc dot gnu.org
@ 2022-12-08 8:44 ` amonakov at gcc dot gnu.org
2022-12-12 7:38 ` amonakov at gcc dot gnu.org
` (5 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: amonakov at gcc dot gnu.org @ 2022-12-08 8:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
--- Comment #9 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
I think this is tree-ldist placing memset(sameZ, 0, zPlaneCount) after the
loop, overwriting conditional 'sameZ[i] = true' assignments that happen in the
loop.
For the smaller testcase from comment #6, -O2 -ftree-loop-distribution is
enough, namely:
works:
gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize
-fno-tree-loop-distribute-patterns
breaks:
gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (8 preceding siblings ...)
2022-12-08 8:44 ` [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign amonakov at gcc dot gnu.org
@ 2022-12-12 7:38 ` amonakov at gcc dot gnu.org
2022-12-27 14:22 ` marxin at gcc dot gnu.org
` (4 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: amonakov at gcc dot gnu.org @ 2022-12-12 7:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
--- Comment #10 from Alexander Monakov <amonakov at gcc dot gnu.org> ---
Looks similar to PR 107323, but needs explicit -ftree-loop-distribution to
trigger.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (9 preceding siblings ...)
2022-12-12 7:38 ` amonakov at gcc dot gnu.org
@ 2022-12-27 14:22 ` marxin at gcc dot gnu.org
2022-12-27 14:23 ` [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b marxin at gcc dot gnu.org
` (3 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-27 14:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |marxin at gcc dot gnu.org
--- Comment #11 from Martin Liška <marxin at gcc dot gnu.org> ---
>
> gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize
This got fixed with r13-1732-g87f46a16ec05beb5 which is a costing revision.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (10 preceding siblings ...)
2022-12-27 14:22 ` marxin at gcc dot gnu.org
@ 2022-12-27 14:23 ` marxin at gcc dot gnu.org
2023-01-09 12:48 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
14 siblings, 0 replies; 16+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-27 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |aldyh at gcc dot gnu.org
Keywords|needs-bisection |
Summary|[12 Regression] wrong code |[12 Regression] wrong code
|with -O3 and posix_memalign |with -O3 and posix_memalign
| |since
| |r12-4526-gd8edfadfc7a9795b
--- Comment #12 from Martin Liška <marxin at gcc dot gnu.org> ---
And it started with r12-4526-gd8edfadfc7a9795b.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (11 preceding siblings ...)
2022-12-27 14:23 ` [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b marxin at gcc dot gnu.org
@ 2023-01-09 12:48 ` rguenth at gcc dot gnu.org
2023-01-09 15:06 ` marxin at gcc dot gnu.org
2023-01-10 8:00 ` rguenth at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-09 12:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
CC| |rguenth at gcc dot gnu.org
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=107323
Known to work| |13.0
Keywords| |needs-bisection
--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Alexander Monakov from comment #9)
> I think this is tree-ldist placing memset(sameZ, 0, zPlaneCount) after the
> loop, overwriting conditional 'sameZ[i] = true' assignments that happen in
> the loop.
>
> For the smaller testcase from comment #6, -O2 -ftree-loop-distribution is
> enough, namely:
>
> works:
>
> gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize
> -fno-tree-loop-distribute-patterns
>
> breaks:
>
> gcc-12 -O2 -ftree-loop-distribution -fno-tree-vectorize
Note I can not reproduce on the branch after r12-8855-g19a9b5e587e87f52,
so maybe that's truly the duplicate.
Bisecting on the branch might reveal that.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (12 preceding siblings ...)
2023-01-09 12:48 ` rguenth at gcc dot gnu.org
@ 2023-01-09 15:06 ` marxin at gcc dot gnu.org
2023-01-10 8:00 ` rguenth at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-01-09 15:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|needs-bisection |
--- Comment #14 from Martin Liška <marxin at gcc dot gnu.org> ---
> Note I can not reproduce on the branch after r12-8855-g19a9b5e587e87f52,
> so maybe that's truly the duplicate.
gcc-12 branch is fixed since the mentioned revision.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
` (13 preceding siblings ...)
2023-01-09 15:06 ` marxin at gcc dot gnu.org
@ 2023-01-10 8:00 ` rguenth at gcc dot gnu.org
14 siblings, 0 replies; 16+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-01-10 8:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108008
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #15 from Richard Biener <rguenth at gcc dot gnu.org> ---
Duplicate then.
*** This bug has been marked as a duplicate of bug 107323 ***
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2023-01-10 8:00 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-07 14:06 [Bug c++/108008] New: Compiler mis-optimization with posix_memalign hahnjo at hahnjo dot de
2022-12-07 14:43 ` [Bug c++/108008] " amonakov at gcc dot gnu.org
2022-12-07 22:12 ` [Bug tree-optimization/108008] " dhsbz at chaw dot com
2022-12-07 22:24 ` pinskia at gcc dot gnu.org
2022-12-07 22:37 ` pinskia at gcc dot gnu.org
2022-12-07 22:48 ` pinskia at gcc dot gnu.org
2022-12-07 22:58 ` pinskia at gcc dot gnu.org
2022-12-07 23:05 ` [Bug tree-optimization/108008] [12 Regression] " pinskia at gcc dot gnu.org
2022-12-07 23:05 ` pinskia at gcc dot gnu.org
2022-12-08 8:44 ` [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign amonakov at gcc dot gnu.org
2022-12-12 7:38 ` amonakov at gcc dot gnu.org
2022-12-27 14:22 ` marxin at gcc dot gnu.org
2022-12-27 14:23 ` [Bug tree-optimization/108008] [12 Regression] wrong code with -O3 and posix_memalign since r12-4526-gd8edfadfc7a9795b marxin at gcc dot gnu.org
2023-01-09 12:48 ` rguenth at gcc dot gnu.org
2023-01-09 15:06 ` marxin at gcc dot gnu.org
2023-01-10 8:00 ` 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).