public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0)
@ 2022-06-03 13:31 theodort at inf dot ethz.ch
2022-06-03 15:27 ` [Bug tree-optimization/105835] " roger at nextmovesoftware dot com
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: theodort at inf dot ethz.ch @ 2022-06-03 13:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105835
Bug ID: 105835
Summary: Dead Code Elimination Regression at -O1 (trunk vs.
12.1.0)
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: theodort at inf dot ethz.ch
Target Milestone: ---
cat case.c
void foo();
static int b;
static short a(short c, unsigned short d) { return c - d; }
int main() {
int e = -(0 < b);
if (a(1, e))
b = 0;
else
foo();
}
`gcc-1982fe2692b6c3b7f969ffc4edac59f9d4359e91 (trunk) -O1` can not eliminate
`foo` but `gcc-releases/gcc-12.1.0 -O1` can.
`gcc-1982fe2692b6c3b7f969ffc4edac59f9d4359e91 (trunk) -O1 -S -o /dev/stdout
case.c`
--------- OUTPUT ---------
main:
.LFB1:
.cfi_startproc
cmpl $0, b(%rip)
movl $65535, %eax
movl $0, %edx
cmovle %edx, %eax
cmpw $1, %ax
je .L2
movl $0, b(%rip)
movl $0, %eax
ret
.L2:
subq $8, %rsp
.cfi_def_cfa_offset 16
movl $0, %eax
call foo
movl $0, %eax
addq $8, %rsp
.cfi_def_cfa_offset 8
ret
---------- END OUTPUT ---------
`gcc-releases/gcc-12.1.0 -O1 -S -o /dev/stdout case.c`
--------- OUTPUT ---------
main:
.LFB1:
.cfi_startproc
movl $0, b(%rip)
movl $0, %eax
ret
---------- END OUTPUT ---------
Bisects to:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8fb94fc6097c0a934aac0d89c9c5e2038da67655
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105835] Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0)
2022-06-03 13:31 [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0) theodort at inf dot ethz.ch
@ 2022-06-03 15:27 ` roger at nextmovesoftware dot com
2022-06-05 19:05 ` roger at nextmovesoftware dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-06-03 15:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105835
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2022-06-03
Ever confirmed|0 |1
--- Comment #1 from Roger Sayle <roger at nextmovesoftware dot com> ---
Hmm. There might be something missing in CCP (with -O1)...
# RANGE [0, 1] NONZERO 1
_3 = (intD.6) _2;
# RANGE [0, 65535] NONZERO 65535
_10 = _3 * 65535;
d_11 = (short unsigned intD.18) _10;
if (d_11 != 1)
goto <bb 3>; [67.00%]
else
goto <bb 4>; [33.00%]
So it knows _10 is either 0 or 65535, so if it knew d_11 had the
range {0 or -1}, i.e. [-1,0] it would know d_11 != 1, and hence
goto <bb 3>.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105835] Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0)
2022-06-03 13:31 [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0) theodort at inf dot ethz.ch
2022-06-03 15:27 ` [Bug tree-optimization/105835] " roger at nextmovesoftware dot com
@ 2022-06-05 19:05 ` roger at nextmovesoftware dot com
2022-06-13 12:37 ` [Bug tree-optimization/105835] [13 Regression] " rguenth at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-06-05 19:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105835
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |roger at nextmovesoftware dot com
--- Comment #2 from Roger Sayle <roger at nextmovesoftware dot com> ---
Patch proposed
https://gcc.gnu.org/pipermail/gcc-patches/2022-June/596200.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105835] [13 Regression] Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0)
2022-06-03 13:31 [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0) theodort at inf dot ethz.ch
2022-06-03 15:27 ` [Bug tree-optimization/105835] " roger at nextmovesoftware dot com
2022-06-05 19:05 ` roger at nextmovesoftware dot com
@ 2022-06-13 12:37 ` rguenth at gcc dot gnu.org
2022-06-18 8:10 ` cvs-commit at gcc dot gnu.org
2022-06-20 17:10 ` roger at nextmovesoftware dot com
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-13 12:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105835
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Dead Code Elimination |[13 Regression] Dead Code
|Regression at -O1 (trunk |Elimination Regression at
|vs. 12.1.0) |-O1 (trunk vs. 12.1.0)
Target Milestone|--- |13.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105835] [13 Regression] Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0)
2022-06-03 13:31 [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0) theodort at inf dot ethz.ch
` (2 preceding siblings ...)
2022-06-13 12:37 ` [Bug tree-optimization/105835] [13 Regression] " rguenth at gcc dot gnu.org
@ 2022-06-18 8:10 ` cvs-commit at gcc dot gnu.org
2022-06-20 17:10 ` roger at nextmovesoftware dot com
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-06-18 8:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105835
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sayle@gcc.gnu.org>:
https://gcc.gnu.org/g:9991d84d2a84355fd3fc9afc89a963f45991bfa9
commit r13-1162-g9991d84d2a84355fd3fc9afc89a963f45991bfa9
Author: Roger Sayle <roger@nextmovesoftware.com>
Date: Sat Jun 18 09:06:20 2022 +0100
PR tree-optimization/105835: Two narrowing patterns for match.pd.
This patch resolves PR tree-optimization/105835, which is a code quality
(dead code elimination) regression at -O1 triggered/exposed by a recent
change to canonicalize X&-Y as X*Y. The new (shorter) form exposes some
missed optimization opportunities that can be handled by adding some
extra simplifications to match.pd.
One transformation is to simplify "(short)(x ? 65535 : 0)" into the
equivalent "x ? -1 : 0", or more accurately x ? (short)-1 : (short)0",
as INTEGER_CSTs record their type, and integer conversions can be
pushed inside COND_EXPRs reducing the number of gimple statements.
The other transformation is that (short)(X * 65535), where X is [0,1],
into the equivalent (short)X * -1, (or again (short)-1 where tree's
INTEGER_CSTs encode their type). This is valid because multiplications
where one operand is [0,1] are guaranteed not to overflow, and hence
integer conversions can also be pushed inside these multiplications.
These narrowing conversion optimizations can be identified by range
analyses, such as EVRP, but these are only performed at -O2 and above,
which is why this regression is only visible with -O1.
2022-06-18 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR tree-optimization/105835
* match.pd (convert (mult zero_one_valued_p@1 INTEGER_CST@2)):
Narrow integer multiplication by a zero_one_valued_p operand.
(convert (cond @1 INTEGER_CST@2 INTEGER_CST@3)): Push integer
conversions inside COND_EXPR where both data operands are
integer constants.
gcc/testsuite/ChangeLog
PR tree-optimization/105835
* gcc.dg/pr105835.c: New test case.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/105835] [13 Regression] Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0)
2022-06-03 13:31 [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0) theodort at inf dot ethz.ch
` (3 preceding siblings ...)
2022-06-18 8:10 ` cvs-commit at gcc dot gnu.org
@ 2022-06-20 17:10 ` roger at nextmovesoftware dot com
4 siblings, 0 replies; 6+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-06-20 17:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105835
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Roger Sayle <roger at nextmovesoftware dot com> ---
This should now be fixed on mainline.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-06-20 17:10 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-03 13:31 [Bug tree-optimization/105835] New: Dead Code Elimination Regression at -O1 (trunk vs. 12.1.0) theodort at inf dot ethz.ch
2022-06-03 15:27 ` [Bug tree-optimization/105835] " roger at nextmovesoftware dot com
2022-06-05 19:05 ` roger at nextmovesoftware dot com
2022-06-13 12:37 ` [Bug tree-optimization/105835] [13 Regression] " rguenth at gcc dot gnu.org
2022-06-18 8:10 ` cvs-commit at gcc dot gnu.org
2022-06-20 17:10 ` roger at nextmovesoftware dot com
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).