public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
@ 2023-06-15 16:22 theodort at inf dot ethz.ch
2023-06-15 16:45 ` [Bug tree-optimization/110269] [13/14 " pinskia at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-06-15 16:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Bug ID: 110269
Summary: 13/14 Regression] Missed Dead Code Elimination when
using __builtin_unreachable since
r13-4607-g2dc5d6b1e7e
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/5qqPMsxEh
Given the following code:
void foo(void);
static int a = 1, c;
static int *b = &a;
static int **d = &b;
static int ***e = &d;
void __assert_fail() __attribute__((__noreturn__));
static int f() {
if (a) return a;
for (; c;) *e = 0;
if (b) __assert_fail();
return 6;
}
int main() {
if (f()) {
*d = 0;
if (b == 0)
;
else {
__builtin_unreachable();
__assert_fail();
}
}
if (b == 0)
;
else
foo();
;
}
gcc-trunk -O3 generates:
main:
subq $8, %rsp
movl a(%rip), %eax
testl %eax, %eax
jne .L2
cmpq $0, b(%rip)
jne .L6
.L2:
movq d(%rip), %rax
movq $0, (%rax)
cmpq $0, b(%rip)
je .L3
call foo
.L3:
xorl %eax, %eax
addq $8, %rsp
ret
.L6:
xorl %eax, %eax
call __assert_fail
gcc-12.3.0 -O3 generates:
main:
movl a(%rip), %edx
testl %edx, %edx
jne .L2
cmpq $0, b(%rip)
jne .L7
.L2:
movq d(%rip), %rax
movq $0, (%rax)
xorl %eax, %eax
ret
.L7:
pushq %rax
xorl %eax, %eax
call __assert_fail
Bisects to r13-4607-g2dc5d6b1e7e
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
@ 2023-06-15 16:45 ` pinskia at gcc dot gnu.org
2023-06-15 17:04 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-15 16:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Target Milestone|--- |13.2
Ever confirmed|0 |1
Keywords| |missed-optimization
Last reconfirmed| |2023-06-15
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC 12.3 ccp2:
```
Folding statement: _20 = _15;
Queued stmt for removal. Folds to: _15
Folding statement: _1 = _20;
Queued stmt for removal. Folds to: _15
Folding statement: if (_1 != 0)
Matching expression match.pd:2119, gimple-match.cc:819
Matching expression match.pd:2122, gimple-match.cc:892
Matching expression match.pd:2129, gimple-match.cc:952
which is likely CONSTANT
Matching expression match.pd:2119, generic-match.cc:693
Matching expression match.pd:2122, generic-match.cc:753
Matching expression match.pd:2129, generic-match.cc:776
Folding predicate _15 != 0 to 1
Folded into: if (1 != 0)
```
GCC 13+ ccp2:
```
Folding statement: _20 = _15;
Queued stmt for removal. Folds to: _15
Folding statement: _1 = _20;
Queued stmt for removal. Folds to: _15
Folding statement: if (_1 != 0)
Matching expression match.pd:2404, gimple-match.cc:852
Matching expression match.pd:2407, gimple-match.cc:925
Matching expression match.pd:2414, gimple-match.cc:985
which is likely CONSTANT
Matching expression match.pd:2404, gimple-match.cc:852
Matching expression match.pd:2407, gimple-match.cc:925
Matching expression match.pd:2414, gimple-match.cc:985
Folded into: if (_15 != 0)
```
oh it was the ccp_fold change that misses it ...
But why I have not looked.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
2023-06-15 16:45 ` [Bug tree-optimization/110269] [13/14 " pinskia at gcc dot gnu.org
@ 2023-06-15 17:04 ` pinskia at gcc dot gnu.org
2023-06-16 6:49 ` rguenth at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-06-15 17:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Maybe gimple_fold_stmt_to_constant_1 should handle GIMPLE_COND ...
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
2023-06-15 16:45 ` [Bug tree-optimization/110269] [13/14 " pinskia at gcc dot gnu.org
2023-06-15 17:04 ` pinskia at gcc dot gnu.org
@ 2023-06-16 6:49 ` rguenth at gcc dot gnu.org
2023-06-16 8:26 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-16 6:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
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 #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
It does handle GIMPLE_COND. What the change did was avoid using GENERIC
fold_const and instead resort to match.pd only. I can't see how it
arrived at folding it before. We (now) have
Visiting PHI node: _15 = PHI <a.3_11(2), 6(5)>
Argument #0 (2 -> 7 executable)
a.3_11 Value: CONSTANT a.3_11
Argument #1 (5 -> 7 executable)
6 Value: CONSTANT 6
PHI node value: VARYING
Lattice value changed to VARYING. Adding SSA edges to worklist.
so there's no nonzero bits info. The input to CCP2 is almost the
same:
int main ()
{
- int D.2014;
+ int D.2786;
int _1;
int * * d.0_2;
int * b.1_3;
@@ -46,7 +46,7 @@
__assert_fail ();
<bb 7> [local count: 1073458354]:
- # RANGE ~[0, 0]
+ # RANGE [irange] int [-INF, -1][1, +INF]
# _15 = PHI <a.3_11(2), 6(5)>
_20 = _15;
_1 = _20;
so it looks like range representation changes make a difference here?
Ah, so match.pd lacks a simple (ne @0 integer_zerop) check using
tree_single_nonzero_warnv_p. We have
(simplify
(cmp (convert? addr@0) integer_zerop)
(if (tree_single_nonzero_warnv_p (@0, NULL))
{ constant_boolean_node (cmp == NE_EXPR, type); }))
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
` (2 preceding siblings ...)
2023-06-16 6:49 ` rguenth at gcc dot gnu.org
@ 2023-06-16 8:26 ` cvs-commit at gcc dot gnu.org
2023-06-16 11:46 ` [Bug tree-optimization/110269] [13 " rguenth at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-16 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
--- Comment #4 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:827e208fa64771f15fc8e53970a2297e637277b5
commit r14-1880-g827e208fa64771f15fc8e53970a2297e637277b5
Author: Richard Biener <rguenther@suse.de>
Date: Fri Jun 16 08:55:12 2023 +0200
tree-optimization/110269 - restore missed condition folding
The following makes sure we optimize x != 0 using range info
via tree_expr_nonzero_p via match.pd.
PR tree-optimization/110269
* fold-const.cc (fold_binary_loc): Merge x != 0 folding
with tree_expr_nonzero_p ...
* match.pd (cmp (convert? addr@0) integer_zerop): With this
pattern.
* gcc.dg/tree-ssa/pr110269.c: New testcase.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
` (3 preceding siblings ...)
2023-06-16 8:26 ` cvs-commit at gcc dot gnu.org
@ 2023-06-16 11:46 ` rguenth at gcc dot gnu.org
2023-07-27 9:26 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-06-16 11:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Bug 110269 depends on bug 110278, which changed state.
Bug 110278 Summary: [14 Regression] FAIL: gcc.dg/tree-ssa/pr103257-1.c scan-tree-dump-times optimized "link_error" 0 from r14-1880-g827e208fa64771
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110278
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
` (4 preceding siblings ...)
2023-06-16 11:46 ` [Bug tree-optimization/110269] [13 " rguenth at gcc dot gnu.org
@ 2023-07-27 9:26 ` rguenth at gcc dot gnu.org
2024-05-13 11:33 ` rguenth at gcc dot gnu.org
2024-05-21 9:15 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-27 9:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.2 |13.3
--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 13.2 is being released, retargeting bugs to GCC 13.3.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
` (5 preceding siblings ...)
2023-07-27 9:26 ` rguenth at gcc dot gnu.org
@ 2024-05-13 11:33 ` rguenth at gcc dot gnu.org
2024-05-21 9:15 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-13 11:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug tree-optimization/110269] [13 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
` (6 preceding siblings ...)
2024-05-13 11:33 ` rguenth at gcc dot gnu.org
@ 2024-05-21 9:15 ` jakub at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-21 9:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110269
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|13.3 |13.4
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 13.3 is being released, retargeting bugs to GCC 13.4.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-05-21 9:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 16:22 [Bug tree-optimization/110269] New: 13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-4607-g2dc5d6b1e7e theodort at inf dot ethz.ch
2023-06-15 16:45 ` [Bug tree-optimization/110269] [13/14 " pinskia at gcc dot gnu.org
2023-06-15 17:04 ` pinskia at gcc dot gnu.org
2023-06-16 6:49 ` rguenth at gcc dot gnu.org
2023-06-16 8:26 ` cvs-commit at gcc dot gnu.org
2023-06-16 11:46 ` [Bug tree-optimization/110269] [13 " rguenth at gcc dot gnu.org
2023-07-27 9:26 ` rguenth at gcc dot gnu.org
2024-05-13 11:33 ` rguenth at gcc dot gnu.org
2024-05-21 9:15 ` jakub 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).