* [Bug tree-optimization/104515] [11/12 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
@ 2022-02-14 9:32 ` rguenth at gcc dot gnu.org
2022-02-15 20:28 ` gcc at rabensky dot com
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-14 9:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-02-14
Ever confirmed|0 |1
Priority|P3 |P2
Component|rtl-optimization |tree-optimization
Summary|trivially-destructible |[11/12 Regression]
|destructors interfere with |trivially-destructible
|loop optimization - maybe |destructors interfere with
|related to lifetime-dse. |loop optimization - maybe
| |related to lifetime-dse.
CC| |jakub at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Target Milestone|--- |11.3
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. The issue is that store motion of v_7(D)->end cannot be performed
on
<bb 3> [local count: 955630225]:
# i_13 = PHI <i_10(6), 0(5)>
_1 = v_7(D)->end;
_2 = _1 + 18446744073709551612;
v_7(D)->end = _2;
MEM[(T *)_1 + -4B] ={v} {CLOBBER}; // <- inserted by -flifetime-dse
i_10 = i_13 + 1;
if (n_6(D) > i_10)
goto <bb 6>; [89.00%]
else
goto <bb 4>; [11.00%]
<bb 6> [local count: 850510901]:
goto <bb 3>; [100.00%]
With GCC 10 we didn't have this particular CLOBBER and at least in GCC 10 the
first testcase was properly optimized.
Note there's a dependence on the value of v_7(D)->end for the clobber so
the clobber itself cannot be moved out of the loop. So the only option
here would be to drop it if it enables store-motion.
We remove all *ssaname_N ={v} {CLOBBER} stmts during the fold-all-builtins
pass but that's very late, in particular _after_ the last CDDCE. I suspect
that instead of
NEXT_PASS (pass_dse);
NEXT_PASS (pass_cd_dce, true /* update_address_taken_p */);
/* After late CD DCE we rewrite no longer addressed locals into SSA
form if possible. */
NEXT_PASS (pass_forwprop);
NEXT_PASS (pass_phiopt, false /* early_p */);
NEXT_PASS (pass_fold_builtins);
we might consider doing FAB (or the CLOBBER removal part) after the last
DSE (or simply direct that last DSE pass do that, with some pass specific
flag). Note that's still too late since we need store-motion here.
Doing the *ssaname_N ={v} {CLOBBER} clobber removal after the _first_
DSE after IPA inlining would be another option. Likewise of course
removing it as part of SM as said above.
I can see how easy it is to do from store-motion.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
2022-02-14 9:32 ` [Bug tree-optimization/104515] [11/12 Regression] " rguenth at gcc dot gnu.org
@ 2022-02-15 20:28 ` gcc at rabensky dot com
2022-02-15 21:02 ` redi at gcc dot gnu.org
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: gcc at rabensky dot com @ 2022-02-15 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #2 from GBE <gcc at rabensky dot com> ---
I don't know if it helps - but I used git-bisect to find the original commit
that added this issue: cdc184174ce
https://github.com/gcc-mirror/gcc/commit/cdc184174ce
It indeed has to do with trivial destructors and clobber and lifetime-dse, so
that confirms it.
It's a fairly small commit - but it's beyond my knowledge of the codebase to
understand it.
I hope it's helpful!
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
2022-02-14 9:32 ` [Bug tree-optimization/104515] [11/12 Regression] " rguenth at gcc dot gnu.org
2022-02-15 20:28 ` gcc at rabensky dot com
@ 2022-02-15 21:02 ` redi at gcc dot gnu.org
2022-02-23 18:22 ` gcc at rabensky dot com
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: redi at gcc dot gnu.org @ 2022-02-15 21:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
aka r9-84-gcdc184174ce56d
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (2 preceding siblings ...)
2022-02-15 21:02 ` redi at gcc dot gnu.org
@ 2022-02-23 18:22 ` gcc at rabensky dot com
2022-04-21 7:51 ` rguenth at gcc dot gnu.org
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: gcc at rabensky dot com @ 2022-02-23 18:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #4 from GBE <gcc at rabensky dot com> ---
The commit that make this issue affect "basic types" as well:
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;h=e443d821386
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (3 preceding siblings ...)
2022-02-23 18:22 ` gcc at rabensky dot com
@ 2022-04-21 7:51 ` rguenth at gcc dot gnu.org
2023-04-12 14:05 ` [Bug tree-optimization/104515] [11/12/13 " rguenth at gcc dot gnu.org
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-21 7:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.3 |11.4
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11.3 is being released, retargeting bugs to GCC 11.4.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (4 preceding siblings ...)
2022-04-21 7:51 ` rguenth at gcc dot gnu.org
@ 2023-04-12 14:05 ` rguenth at gcc dot gnu.org
2023-04-17 13:02 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-12 14:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pshevchuk at pshevchuk dot com
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
*** Bug 109486 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (5 preceding siblings ...)
2023-04-12 14:05 ` [Bug tree-optimization/104515] [11/12/13 " rguenth at gcc dot gnu.org
@ 2023-04-17 13:02 ` rguenth at gcc dot gnu.org
2023-05-29 10:06 ` [Bug tree-optimization/104515] [11/12/13/14 " jakub at gcc dot gnu.org
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-17 13:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> Confirmed. The issue is that store motion of v_7(D)->end cannot be
> performed on
>
> <bb 3> [local count: 955630225]:
> # i_13 = PHI <i_10(6), 0(5)>
> _1 = v_7(D)->end;
> _2 = _1 + 18446744073709551612;
> v_7(D)->end = _2;
> MEM[(T *)_1 + -4B] ={v} {CLOBBER}; // <- inserted by -flifetime-dse
> i_10 = i_13 + 1;
> if (n_6(D) > i_10)
> goto <bb 6>; [89.00%]
> else
> goto <bb 4>; [11.00%]
>
> <bb 6> [local count: 850510901]:
> goto <bb 3>; [100.00%]
It's possible to perform store-motion of the above as the following,
preserving the CLOBBER in the loop but necessarily re-issueing the
last iteration CLOBBER on the exit edge. I _think_ that's fine to do.
The oacc-kernels pipeline does LIM quite early before IPA. For the
later LIM passes we might as well go with eliminating the non-decl
CLOBBERs earlier - but the issue also exists for decl CLOBBERs of course.
Note duplicating "lifetime" CLOBBERs might prove bad (we only have EOL
clobbers right now).
<bb 3> [local count: 955630225]:
# i_13 = PHI <i_10(6), 0(5)>
# v__end_lsm.3_4 = PHI <v__end_lsm.3_12(6), v__end_lsm.3_3(5)>
_1 = v__end_lsm.3_4;
_2 = _1 + 18446744073709551612;
v__end_lsm.3_12 = _2;
MEM[(int *)_1 + -4B] ={v} {CLOBBER};
i_10 = i_13 + 1;
if (n_6(D) > i_10)
goto <bb 6>; [89.00%]
else
goto <bb 7>; [11.00%]
<bb 6> [local count: 850510901]:
goto <bb 3>; [100.00%]
<bb 7> [local count: 105119324]:
# _17 = PHI <_1(3)>
# v__end_lsm.3_19 = PHI <v__end_lsm.3_12(3)>
v_7(D)->end = v__end_lsm.3_19;
MEM[(int *)_17 + -4B] ={v} {CLOBBER};
<bb 4> [local count: 118111600]:
return;
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13/14 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (6 preceding siblings ...)
2023-04-17 13:02 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:06 ` jakub at gcc dot gnu.org
2024-07-17 8:37 ` [Bug tree-optimization/104515] [11/12/13/14/15 " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.4 |11.5
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13/14/15 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (7 preceding siblings ...)
2023-05-29 10:06 ` [Bug tree-optimization/104515] [11/12/13/14 " jakub at gcc dot gnu.org
@ 2024-07-17 8:37 ` rguenth at gcc dot gnu.org
2024-07-17 8:42 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-07-17 8:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think not re-emitting the clobber on the exit might be OK semantically - it's
at most a missed optimization for a store. I think it's also OK for the
stack slot sharing logic as any object becoming live after a clobber
would need to have a mention inbetween the clobber and the exit. I'll note
that if that's not OK then duplicating the clobber wouldn't either.
As we don't know whether the object we store to ends its lifetime (it's only
a may-alias) we can't do both - extend its lifetime and preserve the
original one.
We could maybe move the clobber (duplicating it to each edge but removing
it from the loop body).
I'm testing a patch.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13/14/15 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (8 preceding siblings ...)
2024-07-17 8:37 ` [Bug tree-optimization/104515] [11/12/13/14/15 " rguenth at gcc dot gnu.org
@ 2024-07-17 8:42 ` rguenth at gcc dot gnu.org
2024-07-18 7:44 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-07-17 8:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #10 from Richard Biener <rguenth at gcc dot gnu.org> ---
Testcase from PR96717, also fixed with my patch in testing.
#include <vector>
void pop_many(std::vector<int>& v, unsigned n) {
for (unsigned i = 0; i < n; ++i) {
v.pop_back();
}
}
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13/14/15 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (9 preceding siblings ...)
2024-07-17 8:42 ` rguenth at gcc dot gnu.org
@ 2024-07-18 7:44 ` cvs-commit at gcc dot gnu.org
2024-07-18 7:46 ` [Bug tree-optimization/104515] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-07-19 13:15 ` [Bug tree-optimization/104515] [12/13/14 " rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-07-18 7:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:8c67dc40459e3d72e8169b099cc8c5dbdb759da3
commit r15-2133-g8c67dc40459e3d72e8169b099cc8c5dbdb759da3
Author: Richard Biener <rguenther@suse.de>
Date: Wed Jul 17 10:22:47 2024 +0200
tree-optimization/104515 - store motion and clobbers
The following addresses an old regression when end-of-object/storage
clobbers were introduced. In particular when there's an end-of-object
clobber in a loop but no corresponding begin-of-object we can still
perform store motion of may-aliased refs when we re-issue the
end-of-object/storage on the exits but elide it from the loop. This
should be the safest way to deal with this considering stack-slot
sharing and it should not cause missed dead store eliminations given
DSE can now follow multiple paths in case there are multiple exits.
Note when the clobber is re-materialized only on one exit but not
on anther we are erroring on the side of removing the clobber on
such path. This should be OK (removing clobbers is always OK).
Note there's no corresponding code to handle begin-of-object/storage
during the hoisting part of loads that are part of a store motion
optimization, so this only enables stored-only store motion or cases
without such clobber inside the loop.
PR tree-optimization/104515
* tree-ssa-loop-im.cc (execute_sm_exit): Add clobbers_to_prune
parameter and handle re-materializing of clobbers.
(sm_seq_valid_bb): end-of-storage/object clobbers are OK inside
an ordered sequence of stores.
(sm_seq_push_down): Refuse to push down clobbers.
(hoist_memory_references): Prune clobbers from the loop body
we re-materialized on an exit.
* g++.dg/opt/pr104515.C: New testcase.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [11/12/13/14 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (10 preceding siblings ...)
2024-07-18 7:44 ` cvs-commit at gcc dot gnu.org
@ 2024-07-18 7:46 ` rguenth at gcc dot gnu.org
2024-07-19 13:15 ` [Bug tree-optimization/104515] [12/13/14 " rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-07-18 7:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to work| |15.0
Summary|[11/12/13/14/15 Regression] |[11/12/13/14 Regression]
|trivially-destructible |trivially-destructible
|destructors interfere with |destructors interfere with
|loop optimization - maybe |loop optimization - maybe
|related to lifetime-dse. |related to lifetime-dse.
--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
This has been fixed for GCC 15, it's unlikely backported but I'll leave this
open for tracking purposes.
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bug tree-optimization/104515] [12/13/14 Regression] trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse.
2022-02-12 20:16 [Bug rtl-optimization/104515] New: trivially-destructible destructors interfere with loop optimization - maybe related to lifetime-dse gcc at rabensky dot com
` (11 preceding siblings ...)
2024-07-18 7:46 ` [Bug tree-optimization/104515] [11/12/13/14 " rguenth at gcc dot gnu.org
@ 2024-07-19 13:15 ` rguenth at gcc dot gnu.org
12 siblings, 0 replies; 14+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-07-19 13:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104515
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|11.5 |12.5
--- Comment #13 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 11 branch is being closed.
^ permalink raw reply [flat|nested] 14+ messages in thread