public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/114524] New: Use less expensive expression when expressions are equal
@ 2024-03-28 18:09 goon.pri.low at gmail dot com
2024-03-28 18:11 ` [Bug tree-optimization/114524] " pinskia at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: goon.pri.low at gmail dot com @ 2024-03-28 18:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114524
Bug ID: 114524
Summary: Use less expensive expression when expressions are
equal
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: goon.pri.low at gmail dot com
Target Milestone: ---
When we know multiple expressions are equal, we should only evaluate the least
expensive one.
Example functions:
int a(int b, int *restrict c) {
if (b != *c) __builtin_unreachable();
return *c;
}
int b(int b, int c) {
if (b != c + 1) __builtin_unreachable();
return c + 1;
}
int c(int b, struct {int a; int b;} c) {
if (b != c.b) __builtin_unreachable();
return c.b;
}
int d(int b, int c) {
if (b * 44 != c / 10) __builtin_unreachable();
return c / 10;
}
Generated assembly:
a:
mov eax, DWORD PTR [rsi]
ret
b:
lea eax, [rsi+1]
ret
c:
shr rsi, 32
mov eax, esi
ret
d:
movsx rax, esi
sar esi, 31
imul rax, rax, 1717986919
sar rax, 34
sub eax, esi
ret
Optimal assembly (clang)
a: # @a
mov eax, edi
ret
b: # @b
mov eax, edi
ret
c: # @c
mov eax, edi
ret
d: # @d
imul eax, edi, 44
ret
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug tree-optimization/114524] Use less expensive expression when expressions are equal
2024-03-28 18:09 [Bug rtl-optimization/114524] New: Use less expensive expression when expressions are equal goon.pri.low at gmail dot com
@ 2024-03-28 18:11 ` pinskia at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-28 18:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114524
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-03-28 18:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 18:09 [Bug rtl-optimization/114524] New: Use less expensive expression when expressions are equal goon.pri.low at gmail dot com
2024-03-28 18:11 ` [Bug tree-optimization/114524] " 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).