public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
@ 2023-08-07 10:42 theodort at inf dot ethz.ch
2023-08-07 12:08 ` [Bug tree-optimization/110932] " rguenth at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-08-07 10:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110932
Bug ID: 110932
Summary: [14 Regression] Dead Code Elimination Regression since
r14-2230-g7e904d6c7f2
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/fs5obnhPP
Given the following code:
void foo(void);
static short a;
static int b, c, f, h, i, k;
static char d, m;
static int *j, *o = &f;
static int **l = &j, **n = &j;
static unsigned p(short g, short) { return g; }
static short(q)(unsigned e) {
if (!(((e) >= 1) && ((e) <= 65531))) {
__builtin_unreachable();
}
return 0;
}
static short r() {
q(&k != 0 | f);
*l = o;
return h;
}
static int *s() {
m = c ?: d ?: m;
b = b ?: a;
a = 0;
return *l;
}
int main() {
char t = 0;
for (; t <= 4; t = t + 2) {
int *u = &i;
if (p(~(r() <= t), *u) > i == i) {
**n = -5L;
if (*u) continue;
**n = 0;
if (t) foo();
break;
}
s();
*u = u != 0;
}
s();
h = 0;
}
gcc-trunk -O3 does not eliminate the call to foo:
main:
subq $8, %rsp
movl h(%rip), %ecx
xorl %edx, %edx
movl i(%rip), %eax
movq $f, j(%rip)
testw %cx, %cx
setle %dl
notl %edx
movswl %dx, %edx
cmpl %edx, %eax
setb %dl
movzbl %dl, %edx
cmpl %eax, %edx
jne .L22
testl %eax, %eax
jne .L23
xorl %edx, %edx
movl %edx, f(%rip)
jmp .L14
.L22:
xorl %eax, %eax
call s.isra.0
movl $1, %eax
movl $1, i(%rip)
.L6:
movq $f, j(%rip)
xorl %edx, %edx
cmpw $2, %cx
setle %dl
notl %edx
movswl %dx, %edx
cmpl %edx, %eax
setb %dl
movzbl %dl, %edx
cmpl %edx, %eax
je .L8
xorl %eax, %eax
call s.isra.0
movl $1, %eax
movl $1, i(%rip)
.L9:
movq $f, j(%rip)
xorl %edx, %edx
cmpw $4, %cx
setle %dl
notl %edx
movswl %dx, %edx
cmpl %edx, %eax
setb %dl
movzbl %dl, %edx
cmpl %edx, %eax
jne .L11
testl %eax, %eax
je .L10
movl $-5, f(%rip)
jmp .L14
.L8:
testl %eax, %eax
jne .L24
.L10:
xorl %eax, %eax
movl %eax, f(%rip)
call foo
.L14:
xorl %eax, %eax
call s.isra.0
xorl %eax, %eax
movl $0, h(%rip)
addq $8, %rsp
ret
.L11:
xorl %eax, %eax
call s.isra.0
movl $1, i(%rip)
jmp .L14
.L23:
movl $-5, f(%rip)
jmp .L6
.L24:
movl $-5, f(%rip)
jmp .L9
gcc-13.2.0 -O3 eliminates the call to foo:
main:
xorl %eax, %eax
cmpw $0, h(%rip)
movl i(%rip), %edx
movq $f, j(%rip)
setle %al
notl %eax
cwtl
cmpl %eax, %edx
setb %al
movzbl %al, %eax
cmpl %edx, %eax
jne .L11
testl %edx, %edx
jne .L6
.L7:
xorl %eax, %eax
movl %edx, f(%rip)
call s.isra.0
xorl %eax, %eax
movl $0, h(%rip)
ret
.L11:
xorl %eax, %eax
call s.isra.0
movl $1, i(%rip)
.L6:
movq $f, j(%rip)
movl $-5, %edx
jmp .L7
Bisects to r14-2230-g7e904d6c7f2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/110932] [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
2023-08-07 10:42 [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2 theodort at inf dot ethz.ch
@ 2023-08-07 12:08 ` rguenth at gcc dot gnu.org
2023-08-19 13:59 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-08-07 12:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110932
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
CC| |hubicka at gcc dot gnu.org
Keywords| |missed-optimization
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/110932] [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
2023-08-07 10:42 [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2 theodort at inf dot ethz.ch
2023-08-07 12:08 ` [Bug tree-optimization/110932] " rguenth at gcc dot gnu.org
@ 2023-08-19 13:59 ` pinskia at gcc dot gnu.org
2023-08-19 14:01 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-19 13:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110932
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Last reconfirmed| |2023-08-19
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
_41 = _43 <= 0;
# RANGE [irange] unsigned short [0, 1] NONZERO 0x1
_40 = (unsigned short) _41;
# RANGE [irange] unsigned short [65534, +INF]
_36 = ~_40;
# RANGE [irange] short int [-2, -1]
_19 = (short intD.17) _36;
# RANGE [irange] unsigned int [4294967294, +INF]
_17 = (unsigned intD.9) _19; // ~(unsigned)_41
// rather _41 ? 4294967294 : 4294967295
i.1_14 = (unsigned intD.9) pretmp_60;
_13 = i.1_14 < _17;
# RANGE [irange] int [0, 1] NONZERO 0x1
_12 = (intD.6) _13;
if (_12 == pretmp_60)
pretmp_60 == (((unsigned intD.9) pretmp_60) < _17)
Which is:
(pretmp_60 == 1 && ((unsigned intD.9) pretmp_60) < _17))
| (pretmp_60 == 0 && ((unsigned intD.9) pretmp_60) >= _17))
Though ((unsigned intD.9) pretmp_60) >= _17) is always false because _17's
range does not include 0.
So we are left with:
(pretmp_60 == 1 && 1 < _17)
But _17's range is always bigger than 0 so we are just left with:
pretmp_60 == 1
So the general rule is:
(simplify
(eq:c @0 (convert (cmp @1 @2)))
(if (bitwise_equal_p (@0, @1))
(with {
bool zeroalwaystrue = ...
bool zeroalwaysfalse = ...
bool onealwaystrue = ...
bool onealwaysfalse = ...
}
(switch
(if (zeroalwaystrue && onealwaystrue)
(le @0:unsigned { one(unsigned); } )) // @0 == 0 | @0 == 1
(if (zeroalwaysfalse && onealwaysfalse )
{ false_bool; }) // false
(if (zeroalwaystrue && onealwaysfalse)
(eq @0 { zero(TREE_TYPE(@0)); })) // @0 == 0
(if (onealwaystrue && onealwaysfalse)
(eq @0 { one(TREE_TYPE(@0)); })) // @0 == 1
Later on instead of `if (_12 == _50)` we would have `if (_50 == 1)`
```
if (_50 == 1)
goto <bb 4>; [51.12%]
else
goto <bb 3>; [48.88%]
...
<bb 4> [local count: 278223726]:
if (_50 != 0)
goto <bb 5>; [33.00%]
else
goto <bb 15>; [67.00%]
```
Which is an obvious case where we know _50 is 1 in bb 4 and therefore !=0.
etc.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/110932] [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
2023-08-07 10:42 [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2 theodort at inf dot ethz.ch
2023-08-07 12:08 ` [Bug tree-optimization/110932] " rguenth at gcc dot gnu.org
2023-08-19 13:59 ` pinskia at gcc dot gnu.org
@ 2023-08-19 14:01 ` pinskia at gcc dot gnu.org
2024-03-07 23:25 ` law at gcc dot gnu.org
2024-05-07 7:41 ` [Bug tree-optimization/110932] [14/15 " rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-19 14:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110932
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> So the general rule is:
> (simplify
> (eq:c @0 (convert (cmp @1 @2)))
> (if (bitwise_equal_p (@0, @1))
> (with {
> bool zeroalwaystrue = ...
> bool zeroalwaysfalse = ...
> bool onealwaystrue = ...
> bool onealwaysfalse = ...
> }
> (switch
> (if (zeroalwaystrue && onealwaystrue)
> (le @0:unsigned { one(unsigned); } )) // @0 == 0 | @0 == 1
> (if (zeroalwaysfalse && onealwaysfalse )
> { false_bool; }) // false
> (if (zeroalwaystrue && onealwaysfalse)
> (eq @0 { zero(TREE_TYPE(@0)); })) // @0 == 0
> (if (onealwaystrue && onealwaysfalse)
> (eq @0 { one(TREE_TYPE(@0)); })) // @0 == 1
If we want to do this only in VRP, we could just use match to match the
sequence and then handle the comparison there ...
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/110932] [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
2023-08-07 10:42 [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2 theodort at inf dot ethz.ch
` (2 preceding siblings ...)
2023-08-19 14:01 ` pinskia at gcc dot gnu.org
@ 2024-03-07 23:25 ` law at gcc dot gnu.org
2024-05-07 7:41 ` [Bug tree-optimization/110932] [14/15 " rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 23:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110932
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
CC| |law at gcc dot gnu.org
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/110932] [14/15 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2
2023-08-07 10:42 [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2 theodort at inf dot ethz.ch
` (3 preceding siblings ...)
2024-03-07 23:25 ` law at gcc dot gnu.org
@ 2024-05-07 7:41 ` rguenth at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-07 7:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110932
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|14.0 |14.2
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 14.1 is being released, retargeting bugs to GCC 14.2.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-07 7:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 10:42 [Bug tree-optimization/110932] New: [14 Regression] Dead Code Elimination Regression since r14-2230-g7e904d6c7f2 theodort at inf dot ethz.ch
2023-08-07 12:08 ` [Bug tree-optimization/110932] " rguenth at gcc dot gnu.org
2023-08-19 13:59 ` pinskia at gcc dot gnu.org
2023-08-19 14:01 ` pinskia at gcc dot gnu.org
2024-03-07 23:25 ` law at gcc dot gnu.org
2024-05-07 7:41 ` [Bug tree-optimization/110932] [14/15 " rguenth 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).