public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
@ 2023-07-04 9:38 theodort at inf dot ethz.ch
2023-07-05 6:44 ` [Bug tree-optimization/110539] " rguenth at gcc dot gnu.org
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-07-04 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Bug ID: 110539
Summary: [14 Regression] Dead Code Elimination Regression at
since r14-338-g1dd154f6407
Product: gcc
Version: 14.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: ---
https://godbolt.org/z/h9vrrj5je
Given the following code:
void foo(void);
static int a, c = 1;
static short b;
static int *d = &c, *e = &a;
static int **f = &d;
void __assert_fail() __attribute__((__noreturn__));
static void g(short h) {
if (*d)
;
else {
if (e) __assert_fail();
if (a) {
__builtin_unreachable();
} else
__assert_fail();
}
if ((((0, 0) || h) == h) + b) *f = 0;
}
int main() {
int i = 0 != 10 & a;
g(i);
*e = 9;
e = 0;
if (d == 0)
;
else
foo();
;
}
gcc-trunk -O2 does not eliminate the call to foo:
main:
subq $8, %rsp
movq d(%rip), %rax
movq e(%rip), %rdx
movl (%rax), %edi
testl %edi, %edi
jne .L2
xorl %eax, %eax
call __assert_fail
.L2:
xorl %ecx, %ecx
xorl %esi, %esi
movq %rcx, d(%rip)
cmpq $0, d(%rip)
movl $9, (%rdx)
movq %rsi, e(%rip)
je .L3
call foo
.L3:
xorl %eax, %eax
popq %rdx
ret
gcc-13.1.0 -O2 eliminates the call to foo:
main:
movq d(%rip), %rax
movq e(%rip), %rdx
movl (%rax), %esi
testl %esi, %esi
jne .L2
pushq %rcx
xorl %eax, %eax
call __assert_fail
.L2:
xorl %eax, %eax
movq %rax, d(%rip)
xorl %eax, %eax
movl $9, (%rdx)
xorl %edx, %edx
movq %rdx, e(%rip)
ret
Bisects to r14-338-g1dd154f6407
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
@ 2023-07-05 6:44 ` rguenth at gcc dot gnu.org
2023-07-06 21:20 ` pinskia at gcc dot gnu.org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-05 6:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
2023-07-05 6:44 ` [Bug tree-optimization/110539] " rguenth at gcc dot gnu.org
@ 2023-07-06 21:20 ` pinskia at gcc dot gnu.org
2023-07-06 21:41 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-06 21:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
Last reconfirmed| |2023-07-06
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
# RANGE [irange] int [0, 1] NONZERO 0x1
i_7 = a.0_1 & 1;
_17 = i_7 != 0;
_12 = (int) _17;
if (i_7 == _12)
So this should have been optimized to _17 = (bool) i_7;
and then if (1)
Maybe it is an order of the stuff in match.pd ...
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
2023-07-05 6:44 ` [Bug tree-optimization/110539] " rguenth at gcc dot gnu.org
2023-07-06 21:20 ` pinskia at gcc dot gnu.org
@ 2023-07-06 21:41 ` pinskia at gcc dot gnu.org
2023-07-06 21:45 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-06 21:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So the difference comes from the order. Before in phiopt we had:
- /* Defer boolean x ? 0 : {1,-1} or x ? {1,-1} : 0 to
- match_simplify_replacement. */
- if (TREE_CODE (TREE_TYPE (lhs)) == BOOLEAN_TYPE
- && (integer_zerop (arg0)
- || integer_zerop (arg1)
- || TREE_CODE (TREE_TYPE (arg0)) == BOOLEAN_TYPE
- || (TYPE_PRECISION (TREE_TYPE (arg0))
- <= TYPE_PRECISION (TREE_TYPE (lhs)))))
- return false;
But now the order is such that `?0:{1,-1}`, `?{1,-1}:0` is handled first.
So what we need to pattern match here is `(convert)zero_one_value_p@0!=0` and
simplify that into just (convert)@0
(for neeq (ne eq)
(simplify
(convert (neeq zero_one_value_p@0 integer_zerop))
(if (neeq == NE_EXPR))
(convert @0)
(bit_xor (convert @0) { build_one_cst (type); } ))
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (2 preceding siblings ...)
2023-07-06 21:41 ` pinskia at gcc dot gnu.org
@ 2023-07-06 21:45 ` pinskia at gcc dot gnu.org
2023-07-06 22:03 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-06 21:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a testcase for the missing optimization (at -O1) which is optimized at
the RTL level (for some targets but not all):
```
int f(int a)
{
int b = a & 1;
int c = b != 0;
return c == b;
}
```
Though it does optimize at -O2 because VRP changes: `b != 0` into `(_Bool)
b_4`.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (3 preceding siblings ...)
2023-07-06 21:45 ` pinskia at gcc dot gnu.org
@ 2023-07-06 22:03 ` pinskia at gcc dot gnu.org
2023-07-06 22:44 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-06 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
yes adding:
/* (convert)(zeroone != 0) into (convert)zeroone */
/* (convert)(zeroone == 0) into ((convert)zeroone)^1 */
(for neeq (ne eq)
(simplify
(convert (neeq zero_one_valued_p@0 integer_zerop))
(if (neeq == NE_EXPR)
(convert @0)
(bit_xor (convert @0) { build_one_cst (type); } ))))
Fixes the original testcase.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (4 preceding siblings ...)
2023-07-06 22:03 ` pinskia at gcc dot gnu.org
@ 2023-07-06 22:44 ` pinskia at gcc dot gnu.org
2023-07-08 0:33 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-06 22:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #4)
> yes adding:
> /* (convert)(zeroone != 0) into (convert)zeroone */
> /* (convert)(zeroone == 0) into ((convert)zeroone)^1 */
> (for neeq (ne eq)
> (simplify
> (convert (neeq zero_one_valued_p@0 integer_zerop))
> (if (neeq == NE_EXPR)
> (convert @0)
> (bit_xor (convert @0) { build_one_cst (type); } ))))
>
>
> Fixes the original testcase.
One simple regression:
/* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = 1;" 1 "dom3"} } */
/* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = 0;" 1 "dom3"} } */
fail now but that is they just don't match the above on accident.
Before:
Replaced 'bufferstep_36' with constant '0'
gimple_simplified to _5 = 1;
Folded to: _5 = 1;
After:
Replaced 'bufferstep_36' with constant '0'
gimple_simplified to bufferstep_23 = 1;
Folded to: bufferstep_23 = 1;
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (5 preceding siblings ...)
2023-07-06 22:44 ` pinskia at gcc dot gnu.org
@ 2023-07-08 0:33 ` pinskia at gcc dot gnu.org
2023-07-11 23:13 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-08 0:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |https://gcc.gnu.org/piperma
| |il/gcc-patches/2023-July/62
| |3881.html
Keywords| |patch
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Patch posted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/623881.html
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (6 preceding siblings ...)
2023-07-08 0:33 ` pinskia at gcc dot gnu.org
@ 2023-07-11 23:13 ` pinskia at gcc dot gnu.org
2023-07-12 7:18 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-11 23:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Depends on| |110293
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> # RANGE [irange] int [0, 1] NONZERO 0x1
> i_7 = a.0_1 & 1;
>
> _17 = i_7 != 0;
> _12 = (int) _17;
> if (i_7 == _12)
Wait that is:
i_7 == (convert) (i_7 != 0);
Which is basically PR 110293. So there is another way of fixing this is
simplifying `i_7 == (convert) (i_7 != 0)` into `(unsigned_type)i_7 <= 1` and
that is always true as `(a.0_1 & 1) <= 1` is always true.
Let me try fixing PR 110293 as the way of fixing this one instead of the patch
which I submitted but has other issues.
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110293
[Bug 110293] Some `A CMP (A NEEQ 0)` is not simplified in some cases
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (7 preceding siblings ...)
2023-07-11 23:13 ` pinskia at gcc dot gnu.org
@ 2023-07-12 7:18 ` pinskia at gcc dot gnu.org
2023-07-12 17:32 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-12 7:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Let me file a different bug for onezero stuff that I tried out ...
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (8 preceding siblings ...)
2023-07-12 7:18 ` pinskia at gcc dot gnu.org
@ 2023-07-12 17:32 ` pinskia at gcc dot gnu.org
2023-07-13 14:55 ` cvs-commit at gcc dot gnu.org
2023-07-13 14:55 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-12 17:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
URL|https://gcc.gnu.org/piperma |https://gcc.gnu.org/piperma
|il/gcc-patches/2023-July/62 |il/gcc-patches/2023-July/62
|3881.html |4293.html
--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
New patch submitted:
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/624293.html
Which also gets rid of the call to foo at -O1 -fstrict-aliasing too (which was
not done in GCC 13 either).
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (9 preceding siblings ...)
2023-07-12 17:32 ` pinskia at gcc dot gnu.org
@ 2023-07-13 14:55 ` cvs-commit at gcc dot gnu.org
2023-07-13 14:55 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-13 14:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:
https://gcc.gnu.org/g:285c9d042e90a7425b37697edc9ec93a1b03b486
commit r14-2501-g285c9d042e90a7425b37697edc9ec93a1b03b486
Author: Andrew Pinski <apinski@marvell.com>
Date: Wed Jul 12 00:33:14 2023 -0700
Fix part of PR 110293: `A NEEQ (A NEEQ CST)` part
This fixes part of PR 110293, for the outer comparison case
being `!=` or `==`. In turn PR 110539 is able to be optimized
again as the if statement for `(a&1) == ((a & 1) != 0)` gets optimized
to `false` early enough to allow FRE/DOM to do a CSE for memory store/load.
OK? Bootstrapped and tested on x86_64-linux with no regressions.
gcc/ChangeLog:
PR tree-optimization/110293
PR tree-optimization/110539
* match.pd: Expand the `x != (typeof x)(x == 0)`
pattern to handle where the inner and outer comparsions
are either `!=` or `==` and handle other constants
than 0.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/pr110293-1.c: New test.
* gcc.dg/tree-ssa/pr110539-1.c: New test.
* gcc.dg/tree-ssa/pr110539-2.c: New test.
* gcc.dg/tree-ssa/pr110539-3.c: New test.
* gcc.dg/tree-ssa/pr110539-4.c: New test.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug tree-optimization/110539] [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
` (10 preceding siblings ...)
2023-07-13 14:55 ` cvs-commit at gcc dot gnu.org
@ 2023-07-13 14:55 ` pinskia at gcc dot gnu.org
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-13 14:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110539
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #11 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-07-13 14:55 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-04 9:38 [Bug tree-optimization/110539] New: [14 Regression] Dead Code Elimination Regression at since r14-338-g1dd154f6407 theodort at inf dot ethz.ch
2023-07-05 6:44 ` [Bug tree-optimization/110539] " rguenth at gcc dot gnu.org
2023-07-06 21:20 ` pinskia at gcc dot gnu.org
2023-07-06 21:41 ` pinskia at gcc dot gnu.org
2023-07-06 21:45 ` pinskia at gcc dot gnu.org
2023-07-06 22:03 ` pinskia at gcc dot gnu.org
2023-07-06 22:44 ` pinskia at gcc dot gnu.org
2023-07-08 0:33 ` pinskia at gcc dot gnu.org
2023-07-11 23:13 ` pinskia at gcc dot gnu.org
2023-07-12 7:18 ` pinskia at gcc dot gnu.org
2023-07-12 17:32 ` pinskia at gcc dot gnu.org
2023-07-13 14:55 ` cvs-commit at gcc dot gnu.org
2023-07-13 14:55 ` 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).