public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/115287] New: Missed optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v`
@ 2024-05-30 4:35 xxs_chy at outlook dot com
2024-05-30 4:46 ` [Bug tree-optimization/115287] " pinskia at gcc dot gnu.org
2024-05-30 5:18 ` xxs_chy at outlook dot com
0 siblings, 2 replies; 3+ messages in thread
From: xxs_chy at outlook dot com @ 2024-05-30 4:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115287
Bug ID: 115287
Summary: Missed optimzation: fold `div(v, a) * b + rem(v, a)`
to `div(v, a) * (b - a) + v`
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: xxs_chy at outlook dot com
Target Milestone: ---
Godbolt example: https://godbolt.org/z/b5va37Tzx
For example:
unsigned char _bin2bcd(unsigned val)
{
return ((val / 10) << 4) + val % 10;
}
can be folded to:
unsigned char new_bin2bcd(unsigned val)
{
return val / 10 * 6 + val;
}
With O3 on x86 generates:
_bin2bcd:
mov edx, edi
mov eax, 3435973837
imul rdx, rax
shr rdx, 35
mov eax, edx
lea edx, [rdx+rdx*4]
add edx, edx
sal eax, 4
sub edi, edx
add eax, edi
ret
new_bin2bcd:
mov eax, edi
mov edx, 3435973837
imul rax, rdx
shr rax, 35
lea eax, [rax+rax*2]
lea eax, [rdi+rax*2]
ret
For this case, "new_bin2bcd" is cheaper.
This C snippet is extracted from
https://github.com/torvalds/linux/blob/master/lib/bcd.c
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/115287] Missed optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v`
2024-05-30 4:35 [Bug rtl-optimization/115287] New: Missed optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v` xxs_chy at outlook dot com
@ 2024-05-30 4:46 ` pinskia at gcc dot gnu.org
2024-05-30 5:18 ` xxs_chy at outlook dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-30 4:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115287
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.
*** This bug has been marked as a duplicate of bug 113105 ***
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug tree-optimization/115287] Missed optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v`
2024-05-30 4:35 [Bug rtl-optimization/115287] New: Missed optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v` xxs_chy at outlook dot com
2024-05-30 4:46 ` [Bug tree-optimization/115287] " pinskia at gcc dot gnu.org
@ 2024-05-30 5:18 ` xxs_chy at outlook dot com
1 sibling, 0 replies; 3+ messages in thread
From: xxs_chy at outlook dot com @ 2024-05-30 5:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115287
--- Comment #2 from XChy <xxs_chy at outlook dot com> ---
(In reply to Andrew Pinski from comment #1)
> Dup.
>
> *** This bug has been marked as a duplicate of bug 113105 ***
Sorry for reporting it again. But I transfer it to rtl-optimization because the
developer told me such optimization should be done during RTL expansion, why is
the report tagged tree-optimization now?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-30 5:18 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-30 4:35 [Bug rtl-optimization/115287] New: Missed optimzation: fold `div(v, a) * b + rem(v, a)` to `div(v, a) * (b - a) + v` xxs_chy at outlook dot com
2024-05-30 4:46 ` [Bug tree-optimization/115287] " pinskia at gcc dot gnu.org
2024-05-30 5:18 ` xxs_chy at outlook dot com
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).