public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/107006] New: Missing optimization: common idiom for external data
@ 2022-09-22  2:27 hpa at zytor dot com
  2022-09-22  2:28 ` [Bug rtl-optimization/107006] " hpa at zytor dot com
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: hpa at zytor dot com @ 2022-09-22  2:27 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107006

            Bug ID: 107006
           Summary: Missing optimization: common idiom for external data
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hpa at zytor dot com
  Target Milestone: ---

Created attachment 53602
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53602&action=edit
C test case source

The only *portable* way in C to deal with external data structures containing
data of specific endianness, possibly unaligned, is to operate on them as byte
(char) arrays.

At least on x86 (which supports arbitrarily aligned loads), gcc *sometimes*
recognize these as single loads, but sometimes not.

In the included test cases, there is a plain C implementation and an
implementation wrapped in a C++ class.

Compiling the former with:

gcc -std=c2x -g -O3 -W -Wall -[cSE] -o bswap.[osi] bswap.c

... recognizes the load idiom for 16-bit numbers but not for 32- or 64-bit
numbers.

Compiling the latter with:

gcc -std=c++20 -g -O3 -E -Wall -[cSE] -o bswapcc.[osi] bswapcc.cc

... *additionally* recognizes the 32-bit load, *but only in the bigendian case*
(that is, it generates a load and a bswap instruction); whereas in the
littleendian -- native -- case, this does not happen!

I am familiar with the used of packed arrays and __builtin_bswap*() for these
accesses, but unfortunately these are gcc-specific.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-09-23  6:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-22  2:27 [Bug rtl-optimization/107006] New: Missing optimization: common idiom for external data hpa at zytor dot com
2022-09-22  2:28 ` [Bug rtl-optimization/107006] " hpa at zytor dot com
2022-09-22  2:28 ` hpa at zytor dot com
2022-09-22  2:28 ` hpa at zytor dot com
2022-09-22  2:29 ` hpa at zytor dot com
2022-09-22  2:30 ` hpa at zytor dot com
2022-09-22  2:30 ` hpa at zytor dot com
2022-09-22  2:30 ` hpa at zytor dot com
2022-09-22  2:31 ` hpa at zytor dot com
2022-09-22  2:32 ` hpa at zytor dot com
2022-09-22  7:08 ` [Bug tree-optimization/107006] " rguenth at gcc dot gnu.org
2022-09-22 14:26 ` hpa at zytor dot com
2022-09-23  6:11 ` rguenth 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).