public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/93328] missed optimization opportunity in deserialization code
[not found] <bug-93328-4@http.gcc.gnu.org/bugzilla/>
@ 2020-03-20 2:42 ` pacoarjonilla at yahoo dot es
2020-03-23 5:35 ` pacoarjonilla at yahoo dot es
` (2 subsequent siblings)
3 siblings, 0 replies; 4+ messages in thread
From: pacoarjonilla at yahoo dot es @ 2020-03-20 2:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93328
Paco Arjonilla <pacoarjonilla at yahoo dot es> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pacoarjonilla at yahoo dot es
--- Comment #2 from Paco Arjonilla <pacoarjonilla at yahoo dot es> ---
Using shifts and bitwise does not optimize either in GCC master, but it does
optimize in CLang.
Take this code:
#include <cstdint>
using type = std::uint32_t;
type foo(type v){
type r = (v << 24) & 0xFF000000;
r += (v << 8) & 0x00FF0000;
r += (v >> 8) & 0x0000FF00;
r += (v >> 24) & 0x000000FF;
return r;
}
CLang assembler output: ( optimize with -O2 )
mov eax, edi
bswap eax
ret
GCC master assembler output: ( optimize with -O2 )
mov eax, edi
mov edx, edi
shr eax, 24
sal edx, 24
add edx, eax
mov eax, edi
shr edi, 8
sal eax, 8
and edi, 65280
and eax, 16711680
add eax, edx
add eax, edi
ret
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/93328] missed optimization opportunity in deserialization code
[not found] <bug-93328-4@http.gcc.gnu.org/bugzilla/>
2020-03-20 2:42 ` [Bug tree-optimization/93328] missed optimization opportunity in deserialization code pacoarjonilla at yahoo dot es
@ 2020-03-23 5:35 ` pacoarjonilla at yahoo dot es
2020-03-30 15:46 ` boris_oncev at hotmail dot com
2020-03-30 15:48 ` boris_oncev at hotmail dot com
3 siblings, 0 replies; 4+ messages in thread
From: pacoarjonilla at yahoo dot es @ 2020-03-23 5:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93328
--- Comment #3 from Paco Arjonilla <pacoarjonilla at yahoo dot es> ---
But this gets optimized indeed!
#include <cstdint>
using type = std::uint32_t;
type foo(type v){
type r = ((v << 24) & 0xFF000000)
| ((v << 8) & 0x00FF0000)
| ((v >> 8) & 0x0000FF00)
| ((v >> 24) & 0x000000FF);
return r;
}
GCC -O2:
foo(unsigned int):
mov eax, edi
bswap eax
ret
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/93328] missed optimization opportunity in deserialization code
[not found] <bug-93328-4@http.gcc.gnu.org/bugzilla/>
2020-03-20 2:42 ` [Bug tree-optimization/93328] missed optimization opportunity in deserialization code pacoarjonilla at yahoo dot es
2020-03-23 5:35 ` pacoarjonilla at yahoo dot es
@ 2020-03-30 15:46 ` boris_oncev at hotmail dot com
2020-03-30 15:48 ` boris_oncev at hotmail dot com
3 siblings, 0 replies; 4+ messages in thread
From: boris_oncev at hotmail dot com @ 2020-03-30 15:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93328
Boris <boris_oncev at hotmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |boris_oncev at hotmail dot com
--- Comment #4 from Boris <boris_oncev at hotmail dot com> ---
*** Bug 94403 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/93328] missed optimization opportunity in deserialization code
[not found] <bug-93328-4@http.gcc.gnu.org/bugzilla/>
` (2 preceding siblings ...)
2020-03-30 15:46 ` boris_oncev at hotmail dot com
@ 2020-03-30 15:48 ` boris_oncev at hotmail dot com
3 siblings, 0 replies; 4+ messages in thread
From: boris_oncev at hotmail dot com @ 2020-03-30 15:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93328
--- Comment #5 from Boris <boris_oncev at hotmail dot com> ---
full code:
https://godbolt.org/z/zjNqYV
template <typename T>
auto reverse(T num) {
// misses optimization when num is int32_t OK for int64_t
auto* bytes = reinterpret_cast<char*>(&num);
// misses optimization for both 32 and 64 bit ints
//auto* bytes = reinterpret_cast<std::byte*>(&num);
constexpr auto size = sizeof(num);
for (int i = 0; i < size / 2; i++) {
std::swap(bytes[i], bytes[size-i-1]);
}
return num;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-30 15:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-93328-4@http.gcc.gnu.org/bugzilla/>
2020-03-20 2:42 ` [Bug tree-optimization/93328] missed optimization opportunity in deserialization code pacoarjonilla at yahoo dot es
2020-03-23 5:35 ` pacoarjonilla at yahoo dot es
2020-03-30 15:46 ` boris_oncev at hotmail dot com
2020-03-30 15:48 ` boris_oncev at hotmail 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).