public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
@ 2021-10-26 15:21 theodort at inf dot ethz.ch
2021-10-27 0:42 ` [Bug tree-optimization/102950] [11/12 " pinskia at gcc dot gnu.org
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: theodort at inf dot ethz.ch @ 2021-10-26 15:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
Bug ID: 102950
Summary: [11 Regression] Dead Code Elimination Regression at
-O3 (trunk&11.2.0 vs 10.3.0)
Product: gcc
Version: 12.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 test.c
void foo(void);
static char a;
static short d(unsigned e) {
char b;
short c;
a = b = e;
if (b)
return 0;
if (1 >= e) {
c = e == 0;
if (c)
foo();
}
return 0;
}
int main() { d(a ^ 233); }
10.3.0 at -O3 can eliminate the call to foo but neither trunk nor 11.2.0 at -O3
can:
gcc-10 -O3 -S test.c -o /dev/stdout
main:
.LFB1:
.cfi_startproc
xorb $-23, a(%rip)
xorl %eax, %eax
ret
.cfi_endproc
gcc-11 -O3 -S test.c -o /dev/stdout
...
main:
.LFB1:
.cfi_startproc
movsbl a(%rip), %eax
xorb $-23, %al
movb %al, a(%rip)
cmpl $1, %eax
ja .L10
testb %al, %al
je .L14
.L10:
xorl %eax, %eax
ret
.L14:
pushq %rax
.cfi_def_cfa_offset 16
call foo
xorl %eax, %eax
popq %rdx
.cfi_def_cfa_offset 8
ret
.cfi_endproc
gcc-trunk -O3 -S test.c -o /dev/stdout
main:
.LFB1:
.cfi_startproc
movsbl a(%rip), %eax
xorb $-23, %al
movb %al, a(%rip)
cmpl $1, %eax
ja .L10
testb %al, %al
je .L14
.L10:
xorl %eax, %eax
ret
.L14:
pushq %rax
.cfi_def_cfa_offset 16
call foo
xorl %eax, %eax
popq %rdx
.cfi_def_cfa_offset 8
ret
.cfi_endproc
gcc-trunk -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.0 20211022 (experimental) (GCC)
Introduced with
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=fcae5121154d1c3382b056bcc2c563cedac28e74
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
@ 2021-10-27 0:42 ` pinskia at gcc dot gnu.org
2021-10-27 2:49 ` hjl.tools at gmail dot com
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-27 0:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.3
Ever confirmed|0 |1
Last reconfirmed| |2021-10-27
Summary|[11 Regression] Dead Code |[11/12 Regression] Dead
|Elimination Regression at |Code Elimination Regression
|-O3 (trunk&11.2.0 vs |at -O3 (trunk&11.2.0 vs
|10.3.0) |10.3.0)
Status|UNCONFIRMED |NEW
Keywords| |missed-optimization
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
In GCC 10, forwprop2 gets:
a.0_1 = a;
_2 = (int) a.0_1;
_3 = _2 ^ 233;
_4 = (unsigned int) _3;
b_7 = (char) _4;
a = b_7;
if (b_7 != 0)
goto <bb 6>; [34.00%]
else
goto <bb 3>; [66.00%]
<bb 3> [local count: 708669601]:
if (_4 <= 1)
goto <bb 4>; [41.00%]
else
goto <bb 6>; [59.00%]
<bb 4> [local count: 290554533]:
if (_4 == 0)
goto <bb 5>; [33.00%]
else
goto <bb 6>; [67.00%]
<bb 5> [local count: 95882995]:
foo ();
While in GCC 11 we get:
a.0_1 = a;
_2 = (int) a.0_1;
_3 = _2 ^ 233;
_4 = (unsigned int) _3;
b_7 = (char) _4;
a = b_7;
if (b_7 != 0)
goto <bb 5>; [34.00%]
else
goto <bb 3>; [66.00%]
<bb 3> [local count: 708669601]:
if (_4 <= 1)
goto <bb 4>; [25.50%]
else
goto <bb 5>; [74.50%]
I still can't figure out why forwprop2 can do it in GCC 10 but not in GCC 11.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
2021-10-27 0:42 ` [Bug tree-optimization/102950] [11/12 " pinskia at gcc dot gnu.org
@ 2021-10-27 2:49 ` hjl.tools at gmail dot com
2021-11-05 19:19 ` amacleod at redhat dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: hjl.tools at gmail dot com @ 2021-10-27 2:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
r11-3685 is bad and r11-3683 is good.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
2021-10-27 0:42 ` [Bug tree-optimization/102950] [11/12 " pinskia at gcc dot gnu.org
2021-10-27 2:49 ` hjl.tools at gmail dot com
@ 2021-11-05 19:19 ` amacleod at redhat dot com
2022-01-18 14:38 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: amacleod at redhat dot com @ 2021-11-05 19:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
--- Comment #3 from Andrew Macleod <amacleod at redhat dot com> ---
Im not sure what the pre-ranger trick was, but the shortcoming we have it the
following:
a.0_1 = a;
_2 = (int) a.0_1;
_3 = _2 ^ 233;
_4 = (unsigned int) _3;
b_8 = (char) _3;
a = b_8;
if (b_8 != 0)
we know
_2 : int [-128, 127]
but when we calculate _3,
[-128, 127] ^ 233 uses the original bitwise XOR code, and it returns VARYING
for that range. therefore We only know _3 is VARYING and therefore
2->3 (F) _3 : int [-INF, -256][0, 0][256, +INF]
2->3 (F) _4 : unsigned int [0, 0][256, 4294967040]
When when we later get to
if (_4 <= 1)
goto <bb 4>; [25.50%]
we're kinda of stuck.
whereas in reality, properly calculated, we'd know that
_3 = [-128, 127], _4 = [-128, 127]
And as you can see on the outgoing edges, we see thru the casts to trim out the
other bits in _3 and _4 on the 2->3 edge, so with those proper inputs, we
would end up with _4 and _3 == [0,0].
so, if no one else gets to it, I'll eventually teach
range-op.cc::operator_bitwise_xor::wi_fold to do something about this. special
case constants, or maybe look at the ranges and if the RHS fits within the LHS
effective precision, produce a better result.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
` (2 preceding siblings ...)
2021-11-05 19:19 ` amacleod at redhat dot com
@ 2022-01-18 14:38 ` rguenth at gcc dot gnu.org
2022-02-01 8:59 ` roger at nextmovesoftware dot com
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-18 14:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
` (3 preceding siblings ...)
2022-01-18 14:38 ` rguenth at gcc dot gnu.org
@ 2022-02-01 8:59 ` roger at nextmovesoftware dot com
2022-04-21 7:50 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-02-01 8:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |roger at nextmovesoftware dot com
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |roger at nextmovesoftware dot com
--- Comment #4 from Roger Sayle <roger at nextmovesoftware dot com> ---
Patch proposed
https://gcc.gnu.org/pipermail/gcc-patches/2022-February/589569.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
` (4 preceding siblings ...)
2022-02-01 8:59 ` roger at nextmovesoftware dot com
@ 2022-04-21 7:50 ` rguenth at gcc dot gnu.org
2022-05-03 18:45 ` [Bug tree-optimization/102950] [11/12/13 " 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-04-21 7:50 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
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] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12/13 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
` (5 preceding siblings ...)
2022-04-21 7:50 ` rguenth at gcc dot gnu.org
@ 2022-05-03 18:45 ` cvs-commit at gcc dot gnu.org
2022-05-07 20:11 ` [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (11.2.0 " roger at nextmovesoftware dot com
2022-11-03 19:01 ` amacleod at redhat dot com
8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-05-03 18:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
--- Comment #6 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:b3e98eb3396e16ae8b20c94916bc2bd7862d2c97
commit r13-89-gb3e98eb3396e16ae8b20c94916bc2bd7862d2c97
Author: Roger Sayle <roger@nextmovesoftware.com>
Date: Tue May 3 14:38:50 2022 -0400
PR tree-optimization/102950: Improved EVRP for signed BIT_XOR_EXPR.
This patch fixes PR tree-optimization/102950, which is a P2 regression,
by providing better range bounds for BIT_XOR_EXPR, BIT_AND_EXPR and
BIT_IOR_EXPR on signed integer types. In general terms, any binary
bitwise operation on sign-extended or zero-extended integer types will
produce results that are themselves sign-extended or zero-extended.
More precisely, we can derive signed bounds from the number of leading
redundant sign bit copies, from the equation:
clrsb(X op Y) >= min (clrsb (X), clrsb(Y))
and from the property that for any (signed or unsigned) range [lb, ub]
that clrsb([lb, ub]) >= min (clrsb(lb), clrsb(ub)).
These can be used to show that [-1, 0] op [-1, 0] is [-1, 0] or that
[-128, 127] op [-128, 127] is [-128, 127], even when tracking nonzero
bits would result in VARYING (as every bit can be 0 or 1). This is
equivalent to determining the minimum type precision in which the
operation can be performed then sign extending the result.
One additional refinement is to observe that X ^ Y can never be
zero if the ranges of X and Y don't overlap, i.e. X can't be equal
to Y.
Previously, the expression "(int)(char)a ^ 233" in the PR was considered
VARYING, but with the above changes now has the range [-256, -1][1, 255],
which is sufficient to optimize away the call to foo.
2022-05-03 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
PR tree-optimization/102950
* range-op.cc (wi_optimize_signed_bitwise_op): New function to
determine bounds of bitwise operations on signed types.
(operator_bitwise_and::wi_fold): Call the above function.
(operator_bitwise_or::wi_fold): Likewise.
(operator_bitwise_xor::wi_fold): Likewise. Additionally, the
result can't be zero if the operands can't be equal.
gcc/testsuite/ChangeLog
PR tree-optimization/102950
* gcc.dg/pr102950.c: New test case.
* gcc.dg/tree-ssa/evrp10.c: New test case.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
` (6 preceding siblings ...)
2022-05-03 18:45 ` [Bug tree-optimization/102950] [11/12/13 " cvs-commit at gcc dot gnu.org
@ 2022-05-07 20:11 ` roger at nextmovesoftware dot com
2022-11-03 19:01 ` amacleod at redhat dot com
8 siblings, 0 replies; 10+ messages in thread
From: roger at nextmovesoftware dot com @ 2022-05-07 20:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
Roger Sayle <roger at nextmovesoftware dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |NEW
Summary|[11/12/13 Regression] Dead |[11/12 Regression] Dead
|Code Elimination Regression |Code Elimination Regression
|at -O3 (trunk&11.2.0 vs |at -O3 (11.2.0 vs 10.3.0)
|10.3.0) |
Target Milestone|11.4 |13.0
Known to work| |13.0
Assignee|roger at nextmovesoftware dot com |unassigned at gcc dot gnu.org
--- Comment #7 from Roger Sayle <roger at nextmovesoftware dot com> ---
This has now been fixed on mainline.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (11.2.0 vs 10.3.0)
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
` (7 preceding siblings ...)
2022-05-07 20:11 ` [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (11.2.0 " roger at nextmovesoftware dot com
@ 2022-11-03 19:01 ` amacleod at redhat dot com
8 siblings, 0 replies; 10+ messages in thread
From: amacleod at redhat dot com @ 2022-11-03 19:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102950
Andrew Macleod <amacleod at redhat dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|NEW |RESOLVED
--- Comment #8 from Andrew Macleod <amacleod at redhat dot com> ---
Fixed. Thanks Roger.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-11-03 19:01 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 15:21 [Bug tree-optimization/102950] New: [11 Regression] Dead Code Elimination Regression at -O3 (trunk&11.2.0 vs 10.3.0) theodort at inf dot ethz.ch
2021-10-27 0:42 ` [Bug tree-optimization/102950] [11/12 " pinskia at gcc dot gnu.org
2021-10-27 2:49 ` hjl.tools at gmail dot com
2021-11-05 19:19 ` amacleod at redhat dot com
2022-01-18 14:38 ` rguenth at gcc dot gnu.org
2022-02-01 8:59 ` roger at nextmovesoftware dot com
2022-04-21 7:50 ` rguenth at gcc dot gnu.org
2022-05-03 18:45 ` [Bug tree-optimization/102950] [11/12/13 " cvs-commit at gcc dot gnu.org
2022-05-07 20:11 ` [Bug tree-optimization/102950] [11/12 Regression] Dead Code Elimination Regression at -O3 (11.2.0 " roger at nextmovesoftware dot com
2022-11-03 19:01 ` amacleod at redhat 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).