public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114722] New: Missed optimization: !e*d*e=>0, affected by useless instructions
@ 2024-04-15 14:17 652023330028 at smail dot nju.edu.cn
2024-04-15 16:37 ` [Bug tree-optimization/114722] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-04-15 14:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114722
Bug ID: 114722
Summary: Missed optimization: !e*d*e=>0, affected by useless
instructions
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: 652023330028 at smail dot nju.edu.cn
Target Milestone: ---
Hello, we noticed that the code below can be optimized as stated in the title
(!e*d*e=>0), but gcc -O3 -fwrapv missed it. It looks like it's affected by some
useless instructions.
https://godbolt.org/z/5vPqcbGWr
extern int x;
extern int y;
void func1(int a, int b, int c, int d, int e) {
a = c;
a = b;
a = d;
x = c;
y = !e * d * e;
}
GCC -O3 -fwrapv:
func1(int, int, int, int, int):
xor eax, eax
test r8d, r8d
mov DWORD PTR x[rip], edx
cmovne ecx, eax
imul ecx, r8d
mov DWORD PTR y[rip], ecx
ret
Expected code (when we remove 'a=c; a=b; a=d;'):
func1(int, int, int, int, int):
mov DWORD PTR x[rip], edx
mov DWORD PTR y[rip], 0
ret
By the way, when the exact same fun1 and func2 appear together, func2 gets the
expected result:
extern int x;
extern int y;
void func1(int a, int b, int c, int d, int e) {
a = c;
a = b;
a = d;
x = c;
y = !e * d * e;
}
void func2(int a, int b, int c, int d, int e) {
a = c;
a = b;
a = d;
x = c;
y = !e * d * e;
}
GCC -O3 -fwrapv:
func1(int, int, int, int, int):
xor eax, eax
test r8d, r8d
mov DWORD PTR x[rip], edx
cmovne ecx, eax
imul ecx, r8d
mov DWORD PTR y[rip], ecx
ret
func2(int, int, int, int, int):
mov DWORD PTR x[rip], edx
mov DWORD PTR y[rip], 0
ret
Thank you very much for your time and effort! We look forward to hearing from
you.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/114722] Missed optimization: !e*d*e=>0, affected by useless instructions
2024-04-15 14:17 [Bug tree-optimization/114722] New: Missed optimization: !e*d*e=>0, affected by useless instructions 652023330028 at smail dot nju.edu.cn
@ 2024-04-15 16:37 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-15 16:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114722
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2024-04-15
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Keywords| |missed-optimization, TREE
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
Working case:
x = c_6(D);
_1 = e_8(D) == 0;
_11 = e_8(D) * d_9(D);
_4 = _1 ? _11 : 0;
vs not working case:
x = c_5(D);
_1 = e_10(D) == 0;
_3 = _1 ? d_7(D) : 0;
_4 = _3 * e_10(D);
In the first case, the rtl optimizers can figure it out back to 0. While in the
second case, it can't.
Not a regression and has only been improved lately.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-15 16:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-15 14:17 [Bug tree-optimization/114722] New: Missed optimization: !e*d*e=>0, affected by useless instructions 652023330028 at smail dot nju.edu.cn
2024-04-15 16:37 ` [Bug tree-optimization/114722] " 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).