public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/43883] missed optimization of constant __int128_t modulus
[not found] <bug-43883-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-23 0:46 ` pinskia at gcc dot gnu.org
2021-12-23 0:51 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-23 0:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43883
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
4.7 produces:
shr rsi, 63
mov rax, rdi
xor edi, edi
add rax, rsi
xor r10d, r10d
mov r9, rax
mov rdx, r10
and r9d, 1
mov rax, r9
sub rax, rsi
sbb rdx, rdi
ret
4.9:
mov rcx, rsi
sar rcx, 63
xor rdi, rcx
mov rdx, rcx
mov rax, rdi
sub rax, rcx
and eax, 1
xor rax, rcx
sub rax, rcx
sbb rdx, rcx
ret
7.1.0-7.3.0, 8.1.0-8.2.0 decides not to inline it:
sub rsp, 8
.cfi_def_cfa_offset 16
mov edx, 2
xor ecx, ecx
call __modti3
add rsp, 8
.cfi_def_cfa_offset 8
ret
And then we are back to the 4.9 code gen for 7.4, 8.3 and 9.x
10.x produces:
mov r10, rsi
mov r8, rdi
sar r10, 63
xor r8, r10
mov rdx, r10
mov rax, r8
sub rax, r10
and eax, 1
xor rax, r10
sub rax, r10
sbb rdx, r10
ret
GCC 11 and trunk is back to the 4.9 code gen
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/43883] missed optimization of constant __int128_t modulus
[not found] <bug-43883-4@http.gcc.gnu.org/bugzilla/>
2021-12-23 0:46 ` [Bug middle-end/43883] missed optimization of constant __int128_t modulus pinskia at gcc dot gnu.org
@ 2021-12-23 0:51 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-23 0:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43883
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |enhancement
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note LLVM produces:
mov rdx, rsi
mov rax, rdi
mov rcx, rsi
shr rcx, 63
add rcx, rdi
adc rsi, 0
and rcx, -2
sub rax, rcx
sbb rdx, rsi
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/43883] missed optimization of constant __int128_t modulus
2010-04-25 5:06 [Bug middle-end/43883] New: " svfuerst at gmail dot com
2010-04-30 19:00 ` [Bug middle-end/43883] " ubizjak at gmail dot com
@ 2010-04-30 20:31 ` svfuerst at gmail dot com
1 sibling, 0 replies; 4+ messages in thread
From: svfuerst at gmail dot com @ 2010-04-30 20:31 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from svfuerst at gmail dot com 2010-04-30 20:30 -------
For posterity, I might as well note that with the sbb added on the end we don't
need the initial mov instruction if we do some register renaming. This leaves
the, hopefully optimal this time, five-instruction fragment as the goal:
shr $0x3f,%rsi
lea (%rdi,%rsi,1),%rax
and $0x1,%eax
sub %rsi,%rax
sbb %rdx,%rdx
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43883
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/43883] missed optimization of constant __int128_t modulus
2010-04-25 5:06 [Bug middle-end/43883] New: " svfuerst at gmail dot com
@ 2010-04-30 19:00 ` ubizjak at gmail dot com
2010-04-30 20:31 ` svfuerst at gmail dot com
1 sibling, 0 replies; 4+ messages in thread
From: ubizjak at gmail dot com @ 2010-04-30 19:00 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from ubizjak at gmail dot com 2010-04-30 19:00 -------
(In reply to comment #4)
> Argh, the sar trick doesn't work when the number is negative and even. Sorry
> about the extra noise.
>
> This leaves as the best code:
> mov %rsi,%rdx
> shr $0x3f,%rdx
> lea (%rdi,%rdx,1),%rax
> and $0x1,%eax
> sub %rdx,%rax
> sbb %rdx,%rdx
>
> This is still better than current version. Of course, changing the and
> instruction will allow faster versions of x%4, x%8, x%16 etc.
Belive it or not, but the version that you show in the description is how gcc
handles subregs... it starts OK, but when register allocator comes into play...
Confirmed as RA problem, the same thing happens with "long long" and -m32.
--
ubizjak at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ubizjak at gmail dot com
Status|UNCONFIRMED |NEW
Component|target |middle-end
Ever Confirmed|0 |1
Keywords| |ra
Last reconfirmed|0000-00-00 00:00:00 |2010-04-30 19:00:41
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43883
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-23 0:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-43883-4@http.gcc.gnu.org/bugzilla/>
2021-12-23 0:46 ` [Bug middle-end/43883] missed optimization of constant __int128_t modulus pinskia at gcc dot gnu.org
2021-12-23 0:51 ` pinskia at gcc dot gnu.org
2010-04-25 5:06 [Bug middle-end/43883] New: " svfuerst at gmail dot com
2010-04-30 19:00 ` [Bug middle-end/43883] " ubizjak at gmail dot com
2010-04-30 20:31 ` svfuerst at gmail 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).