public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3)
@ 2022-05-16 13:15 shaohua.li at inf dot ethz.ch
2022-05-16 13:26 ` [Bug tree-optimization/105618] " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-05-16 13:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
Bug ID: 105618
Summary: Missed loop body simplification by -O3 (trunk v.s.
10.3)
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: shaohua.li at inf dot ethz.ch
Target Milestone: ---
For the following code, gcc truck -O3 fails to optimize away the loop body,
while gcc10.3 can. You can see from the assembly code that gcc10.3 figured out
that the variable c would be a constant after the loop while gcc-trunk didn't.
$cat a.c
static int b=4;
int c;
int main() {
int e[5] = {1,1,1,1,1};
for (; b >= 0; b--) {
c = e[b];
}
return 0;
}
$
$gcc-trunk -O3 -S -o trunk.s a.c
$gcc-10-3 -O3 -S -o 10-3.s a.c
$wc trunk.s 10-3.s
66 147 1005 trunk.s
52 106 698 10-3.s
118 253 1703 total
$
$cat 10-3.s
main:
.LFB0:
.cfi_startproc
endbr64
movl b(%rip), %eax
testl %eax, %eax
js .L2
movl $1, c(%rip)
movl $-1, b(%rip)
.L2:
xorl %eax, %eax
ret
$
$cat trunk.s
main:
.LFB0:
.cfi_startproc
movdqa .LC0(%rip), %xmm0
movl b(%rip), %eax
movl $1, -24(%rsp)
movaps %xmm0, -40(%rsp)
testl %eax, %eax
js .L2
movslq %eax, %rdx
leal -1(%rax), %ecx
movl -40(%rsp,%rdx,4), %edx
je .L3
leal -2(%rax), %edx
cmpl $1, %eax
je .L10
leal -3(%rax), %ecx
cmpl $2, %eax
je .L6
leal -4(%rax), %edx
cmpl $3, %eax
je .L10
.L6:
movslq %edx, %rdx
movl -40(%rsp,%rdx,4), %edx
.L3:
movl %edx, c(%rip)
movl $-1, b(%rip)
.L2:
xorl %eax, %eax
ret
.L10:
movslq %ecx, %rcx
movl -40(%rsp,%rcx,4), %edx
jmp .L3
$
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
@ 2022-05-16 13:26 ` pinskia at gcc dot gnu.org
2022-05-17 6:57 ` [Bug tree-optimization/105618] [11/12/13 Regression] " rguenth at gcc dot gnu.org
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-16 13:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
If b was not static and this was not main, there could be undefined behavior.
Gcc does not take into account the function being main though.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11/12/13 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
2022-05-16 13:26 ` [Bug tree-optimization/105618] " pinskia at gcc dot gnu.org
@ 2022-05-17 6:57 ` rguenth at gcc dot gnu.org
2022-05-17 7:32 ` rguenth at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-17 6:57 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
Summary|Missed loop body |[11/12/13 Regression]
|simplification by -O3 |Missed loop body
|(trunk v.s. 10.3) |simplification by -O3
| |(trunk v.s. 10.3)
Target Milestone|--- |11.4
Last reconfirmed| |2022-05-17
Keywords| |missed-optimization,
| |needs-bisection
Known to fail| |11.3.1, 12.1.1
Ever confirmed|0 |1
Known to work| |10.3.1
Status|UNCONFIRMED |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed. GCC 10 manages to sink the load from e out of the loop while GCC 12
fails to do that.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11/12/13 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
2022-05-16 13:26 ` [Bug tree-optimization/105618] " pinskia at gcc dot gnu.org
2022-05-17 6:57 ` [Bug tree-optimization/105618] [11/12/13 Regression] " rguenth at gcc dot gnu.org
@ 2022-05-17 7:32 ` rguenth at gcc dot gnu.org
2022-05-17 7:48 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-17 7:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
There was quite some massaging in handling of PHI uses, notably we now have
/* For PHI nodes the block we know sth about is the incoming
block
with the use. */
if (gimple_code (use_stmt) == GIMPLE_PHI)
{
/* In case the PHI node post-dominates the current insert
location we can disregard it. But make sure it is not
dominating it as well as can happen in a CFG cycle. */
if (commondom != bb
&& !dominated_by_p (CDI_DOMINATORS, commondom, bb)
&& dominated_by_p (CDI_POST_DOMINATORS, commondom, bb)
/* If the blocks are possibly within the same irreducible
cycle the above check breaks down. */
&& !((bb->flags & commondom->flags & BB_IRREDUCIBLE_LOOP)
&& bb->loop_father == commondom->loop_father)
&& !((commondom->flags & BB_IRREDUCIBLE_LOOP)
&& flow_loop_nested_p (commondom->loop_father,
bb->loop_father))
&& !((bb->flags & BB_IRREDUCIBLE_LOOP)
&& flow_loop_nested_p (bb->loop_father,
commondom->loop_father)))
continue;
and already the first !dominated_by_p (CDI_DOMINATORS, commondom, bb) check
makes us not consider the sink opportunity. That was introduced as part
of the fix for PR97330.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11/12/13 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
` (2 preceding siblings ...)
2022-05-17 7:32 ` rguenth at gcc dot gnu.org
@ 2022-05-17 7:48 ` rguenth at gcc dot gnu.org
2022-05-17 8:46 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-17 7:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|needs-bisection |
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I'm testing a patch.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11/12/13 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
` (3 preceding siblings ...)
2022-05-17 7:48 ` rguenth at gcc dot gnu.org
@ 2022-05-17 8:46 ` cvs-commit at gcc dot gnu.org
2022-05-17 8:46 ` [Bug tree-optimization/105618] [11/12 " rguenth at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-17 8:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
--- Comment #5 from CVS 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:ebce0e9bd8d714a8607ae24331a3d842b0d11859
commit r13-550-gebce0e9bd8d714a8607ae24331a3d842b0d11859
Author: Richard Biener <rguenther@suse.de>
Date: Tue May 17 09:45:02 2022 +0200
tree-optimization/105618 - restore load sinking
The PR97330 fix caused some missed sinking of loads out of loops
the following patch re-instantiates.
2022-05-17 Richard Biener <rguenther@suse.de>
PR tree-optimization/105618
* tree-ssa-sink.cc (statement_sink_location): For virtual
PHI uses ignore those defining the used virtual operand.
* gcc.dg/tree-ssa/ssa-sink-19.c: New testcase.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11/12 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
` (4 preceding siblings ...)
2022-05-17 8:46 ` cvs-commit at gcc dot gnu.org
@ 2022-05-17 8:46 ` rguenth at gcc dot gnu.org
2022-05-19 12:47 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-17 8:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[11/12/13 Regression] |[11/12 Regression] Missed
|Missed loop body |loop body simplification by
|simplification by -O3 |-O3 (trunk v.s. 10.3)
|(trunk v.s. 10.3) |
Known to work| |13.0
--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk sofar.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11/12 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
` (5 preceding siblings ...)
2022-05-17 8:46 ` [Bug tree-optimization/105618] [11/12 " rguenth at gcc dot gnu.org
@ 2022-05-19 12:47 ` cvs-commit at gcc dot gnu.org
2022-07-22 11:21 ` [Bug tree-optimization/105618] [11 " cvs-commit at gcc dot gnu.org
2022-07-22 11:22 ` rguenth at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-19 12:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:374cee99d01fceb89d0929da8b38051e6c9768f0
commit r12-8403-g374cee99d01fceb89d0929da8b38051e6c9768f0
Author: Richard Biener <rguenther@suse.de>
Date: Tue May 17 09:45:02 2022 +0200
tree-optimization/105618 - restore load sinking
The PR97330 fix caused some missed sinking of loads out of loops
the following patch re-instantiates.
2022-05-17 Richard Biener <rguenther@suse.de>
PR tree-optimization/105618
* tree-ssa-sink.cc (statement_sink_location): For virtual
PHI uses ignore those defining the used virtual operand.
* gcc.dg/tree-ssa/ssa-sink-19.c: New testcase.
(cherry picked from commit ebce0e9bd8d714a8607ae24331a3d842b0d11859)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
` (6 preceding siblings ...)
2022-05-19 12:47 ` cvs-commit at gcc dot gnu.org
@ 2022-07-22 11:21 ` cvs-commit at gcc dot gnu.org
2022-07-22 11:22 ` rguenth at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-22 11:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:
https://gcc.gnu.org/g:dba0883cbbd0ce7545041be96ae75db1d577affb
commit r11-10169-gdba0883cbbd0ce7545041be96ae75db1d577affb
Author: Richard Biener <rguenther@suse.de>
Date: Tue May 17 09:45:02 2022 +0200
tree-optimization/105618 - restore load sinking
The PR97330 fix caused some missed sinking of loads out of loops
the following patch re-instantiates.
2022-05-17 Richard Biener <rguenther@suse.de>
PR tree-optimization/105618
* tree-ssa-sink.c (statement_sink_location): For virtual
PHI uses ignore those defining the used virtual operand.
* gcc.dg/tree-ssa/ssa-sink-19.c: New testcase.
(cherry picked from commit ebce0e9bd8d714a8607ae24331a3d842b0d11859)
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/105618] [11 Regression] Missed loop body simplification by -O3 (trunk v.s. 10.3)
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
` (7 preceding siblings ...)
2022-07-22 11:21 ` [Bug tree-optimization/105618] [11 " cvs-commit at gcc dot gnu.org
@ 2022-07-22 11:22 ` rguenth at gcc dot gnu.org
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-22 11:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105618
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|11.3.1 |11.3.0
Known to work| |11.3.1
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-07-22 11:22 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 13:15 [Bug tree-optimization/105618] New: Missed loop body simplification by -O3 (trunk v.s. 10.3) shaohua.li at inf dot ethz.ch
2022-05-16 13:26 ` [Bug tree-optimization/105618] " pinskia at gcc dot gnu.org
2022-05-17 6:57 ` [Bug tree-optimization/105618] [11/12/13 Regression] " rguenth at gcc dot gnu.org
2022-05-17 7:32 ` rguenth at gcc dot gnu.org
2022-05-17 7:48 ` rguenth at gcc dot gnu.org
2022-05-17 8:46 ` cvs-commit at gcc dot gnu.org
2022-05-17 8:46 ` [Bug tree-optimization/105618] [11/12 " rguenth at gcc dot gnu.org
2022-05-19 12:47 ` cvs-commit at gcc dot gnu.org
2022-07-22 11:21 ` [Bug tree-optimization/105618] [11 " cvs-commit at gcc dot gnu.org
2022-07-22 11:22 ` 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).