public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated
@ 2021-03-08 20:24 msebor at gcc dot gnu.org
2021-03-08 21:36 ` [Bug tree-optimization/99473] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-03-08 20:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473
Bug ID: 99473
Summary: redundant conditional zero-initialization not
eliminated
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
All three functions below should result in equivalently optimal code (and,
ideally IL) but only g1() and g3() result in the same assembly, and only g1()
result in optimal, branchless GIMPLE.
$ cat x.c && gcc -O2 -S -Wall -o/dev/stdout x.c
void f (int*);
void g1 (int i)
{
int x;
if (i)
x = i;
else
x = 0;
f (&x);
}
void g2 (int i)
{
int x;
if (i) {
x = i;
f (&x);
}
else {
x = 0;
f (&x);
}
}
void g3 (int i)
{
int x = 0;
if (i)
x = i;
f (&x);
}
.file "x.c"
.text
.p2align 4
.globl g1
.type g1, @function
g1:
.LFB0:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32
movl %edi, 12(%rsp)
leaq 12(%rsp), %rdi
call f
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE0:
.size g1, .-g1
.p2align 4
.globl g2
.type g2, @function
g2:
.LFB1:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32
testl %edi, %edi
je .L5
movl %edi, 12(%rsp)
leaq 12(%rsp), %rdi
call f
addq $24, %rsp
.cfi_remember_state
.cfi_def_cfa_offset 8
ret
.p2align 4,,10
.p2align 3
.L5:
.cfi_restore_state
leaq 12(%rsp), %rdi
movl $0, 12(%rsp)
call f
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE1:
.size g2, .-g2
.p2align 4
.globl g3
.type g3, @function
g3:
.LFB2:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32
movl %edi, 12(%rsp)
leaq 12(%rsp), %rdi
call f
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE2:
.size g3, .-g3
.ident "GCC: (GNU) 11.0.1 20210308 (experimental)"
.section .note.GNU-stack,"",@progbits
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/99473] redundant conditional zero-initialization not eliminated
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
@ 2021-03-08 21:36 ` pinskia at gcc dot gnu.org
2021-03-09 8:31 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-03-08 21:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2021-03-08
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, I think there are other bugs dealing with this same thing.
g3 should have been caught by cstore but I don't see why it is not.
Also g2 needs commoning by sinking rather commoning by pulling.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/99473] redundant conditional zero-initialization not eliminated
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
2021-03-08 21:36 ` [Bug tree-optimization/99473] " pinskia at gcc dot gnu.org
@ 2021-03-09 8:31 ` rguenth at gcc dot gnu.org
2021-04-26 9:01 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-03-09 8:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
g3 and g1 behave differently also because of (there's a dup PR I can't find
right now) sinking happening in a way that the pass store-commoning code
doesn't trigger on the sunk store.
cselim doesn't trigger because
if ((TREE_CODE (lhs) != MEM_REF
&& TREE_CODE (lhs) != ARRAY_REF
&& TREE_CODE (lhs) != COMPONENT_REF)
|| !is_gimple_reg_type (TREE_TYPE (lhs)))
return false;
lhs is a VAR_DECL and 'nontrap' only tracks pointers. There's code to actually
handle auto-vars now but the above still disallows bare decls. Because
we have the address-taken the transform will also require
-fallow-store-data-races.
diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
index ddd9d531b13..6f7efa29a1b 100644
--- a/gcc/tree-ssa-phiopt.c
+++ b/gcc/tree-ssa-phiopt.c
@@ -2490,9 +2490,8 @@ cond_store_replacement (basic_block middle_bb,
basic_block join_bb,
locus = gimple_location (assign);
lhs = gimple_assign_lhs (assign);
rhs = gimple_assign_rhs1 (assign);
- if ((TREE_CODE (lhs) != MEM_REF
- && TREE_CODE (lhs) != ARRAY_REF
- && TREE_CODE (lhs) != COMPONENT_REF)
+ if ((!REFERENCE_CLASS_P (lhs)
+ && !DECL_P (lhs))
|| !is_gimple_reg_type (TREE_TYPE (lhs)))
return false;
fixes g3 this (with -fallow-store-data-races). Queued for GCC 12.
g2 needs sinking/commoning of f (&x) for which there's yet another PR I think.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/99473] redundant conditional zero-initialization not eliminated
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
2021-03-08 21:36 ` [Bug tree-optimization/99473] " pinskia at gcc dot gnu.org
2021-03-09 8:31 ` rguenth at gcc dot gnu.org
@ 2021-04-26 9:01 ` cvs-commit at gcc dot gnu.org
2021-04-26 9:02 ` rguenth at gcc dot gnu.org
2023-05-06 23:17 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-04-26 9:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473
--- Comment #3 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:577d05fc914338cd7ddc254f3bee4532331f5c13
commit r12-114-g577d05fc914338cd7ddc254f3bee4532331f5c13
Author: Richard Biener <rguenther@suse.de>
Date: Tue Mar 9 09:29:29 2021 +0100
tree-optimization/99473 - more cselim
This fixes the pre-condition on cselim to include all references
and decls when they end up as auto-var.
Bootstrapped/tested on x86_64-linux
2021-03-09 Richard Biener <rguenther@suse.de>
PR tree-optimization/99473
* tree-ssa-phiopt.c (cond_store_replacement): Handle all
stores.
* gcc.dg/tree-ssa/pr99473-1.c: New testcase.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/99473] redundant conditional zero-initialization not eliminated
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
` (2 preceding siblings ...)
2021-04-26 9:01 ` cvs-commit at gcc dot gnu.org
@ 2021-04-26 9:02 ` rguenth at gcc dot gnu.org
2023-05-06 23:17 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-04-26 9:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|rguenth at gcc dot gnu.org |unassigned at gcc dot gnu.org
Status|ASSIGNED |NEW
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The missed cselim is now fixed. The other cases are dups, but I don't dare
finding them right now ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/99473] redundant conditional zero-initialization not eliminated
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
` (3 preceding siblings ...)
2021-04-26 9:02 ` rguenth at gcc dot gnu.org
@ 2023-05-06 23:17 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-06 23:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99473
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |51964
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
g2 is PR 51964.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51964
[Bug 51964] Missed tail merging opportunity
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-06 23:17 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08 20:24 [Bug tree-optimization/99473] New: redundant conditional zero-initialization not eliminated msebor at gcc dot gnu.org
2021-03-08 21:36 ` [Bug tree-optimization/99473] " pinskia at gcc dot gnu.org
2021-03-09 8:31 ` rguenth at gcc dot gnu.org
2021-04-26 9:01 ` cvs-commit at gcc dot gnu.org
2021-04-26 9:02 ` rguenth at gcc dot gnu.org
2023-05-06 23:17 ` pinskia 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).