public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/114448] New: Roundup not optimized
@ 2024-03-24 14:23 pali at kernel dot org
2024-03-24 18:54 ` [Bug middle-end/114448] " pinskia at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: pali at kernel dot org @ 2024-03-24 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114448
Bug ID: 114448
Summary: Roundup not optimized
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: pali at kernel dot org
Target Milestone: ---
https://godbolt.org/z/4fPKGzs1M
Straightforward code which round up unsigned number to the next multiply of 4
is:
(num % 4 == 0) ? num : num + (4 - num % 4);
gcc -O2 generates:
mov edx, edi
mov eax, edi
and edx, -4
add edx, 4
test dil, 3
cmovne eax, edx
ret
This is not optimal and branch/test can be avoided by using double modulo:
num + (4 - num % 4) % 4;
for which gcc -O2 generates:
mov eax, edi
neg eax
and eax, 3
add eax, edi
ret
Optimal implementation for round up 4 is using bithacks:
(num + 3) & ~3;
for which gcc -O2 generates:
lea eax, [rdi+3]
and eax, -4
ret
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/114448] Roundup not optimized
2024-03-24 14:23 [Bug middle-end/114448] New: Roundup not optimized pali at kernel dot org
@ 2024-03-24 18:54 ` pinskia at gcc dot gnu.org
2024-03-24 18:55 ` pinskia at gcc dot gnu.org
2024-03-24 19:45 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-24 18:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114448
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
Keywords| |missed-optimization
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/114448] Roundup not optimized
2024-03-24 14:23 [Bug middle-end/114448] New: Roundup not optimized pali at kernel dot org
2024-03-24 18:54 ` [Bug middle-end/114448] " pinskia at gcc dot gnu.org
@ 2024-03-24 18:55 ` pinskia at gcc dot gnu.org
2024-03-24 19:45 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-24 18:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114448
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 57799
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57799&action=edit
Full testcase
Please next time attach or put inline the full testcase and not just a link to
godbolt.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/114448] Roundup not optimized
2024-03-24 14:23 [Bug middle-end/114448] New: Roundup not optimized pali at kernel dot org
2024-03-24 18:54 ` [Bug middle-end/114448] " pinskia at gcc dot gnu.org
2024-03-24 18:55 ` pinskia at gcc dot gnu.org
@ 2024-03-24 19:45 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-24 19:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114448
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2024-03-24
Status|UNCONFIRMED |NEW
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-03-24 19:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-24 14:23 [Bug middle-end/114448] New: Roundup not optimized pali at kernel dot org
2024-03-24 18:54 ` [Bug middle-end/114448] " pinskia at gcc dot gnu.org
2024-03-24 18:55 ` pinskia at gcc dot gnu.org
2024-03-24 19:45 ` 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).