public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/111698] New: Narrow memory access of compare to byte width
@ 2023-10-04 20:52 ubizjak at gmail dot com
  2023-10-05  7:51 ` [Bug target/111698] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2023-10-04 20:52 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111698
           Summary: Narrow memory access of compare to byte width
           Product: gcc
           Version: 12.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Following testcase:

--cut here--
int m;

_Bool foo (void)
{
  return m & 0x0f0000;
}
--cut here--

compiles to:

  0:   f7 05 00 00 00 00 00    testl  $0xf0000,0x0(%rip)
  7:   00 0f 00 

The test instruction can be demoted to byte test from addr+2.

Currently, the demotion works for lowest byte, so the testcase:

--cut here--
int m;

_Bool foo (void)
{
  return m & 0x0f;
}
--cut here--

compiles to:

   0:   f6 05 00 00 00 00 0f    testb  $0xf,0x0(%rip)

which is three bytes shorter.

Any half-way modern Intel and AMD cores will forward any fully contained load,
so there is no danger of forwarding stall with recent CPU cores.

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

* [Bug target/111698] Narrow memory access of compare to byte width
  2023-10-04 20:52 [Bug target/111698] New: Narrow memory access of compare to byte width ubizjak at gmail dot com
@ 2023-10-05  7:51 ` rguenth at gcc dot gnu.org
  2023-10-05 11:29 ` ubizjak at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-05  7:51 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*
           Keywords|                            |missed-optimization

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
I guess we could do this even on GIMPLE and in general to aligned sub-word
accesses (where byte accesses are always aligned).

It might be also a good fit for RTL forwprop or that mem-offset pass in
development.

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

* [Bug target/111698] Narrow memory access of compare to byte width
  2023-10-04 20:52 [Bug target/111698] New: Narrow memory access of compare to byte width ubizjak at gmail dot com
  2023-10-05  7:51 ` [Bug target/111698] " rguenth at gcc dot gnu.org
@ 2023-10-05 11:29 ` ubizjak at gmail dot com
  2023-10-24 12:12 ` ubizjak at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2023-10-05 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> I guess we could do this even on GIMPLE and in general to aligned sub-word
> accesses (where byte accesses are always aligned).
> 
> It might be also a good fit for RTL forwprop or that mem-offset pass in
> development.

I don't think this optimization should be universally enabled. According to
Agner Fog, older x86 cores suffer from store forwarding stall when smaller read
doesn't start at the same address. Intel Sandybridge and AMD Steamroller
families relaxed this constraint.

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

* [Bug target/111698] Narrow memory access of compare to byte width
  2023-10-04 20:52 [Bug target/111698] New: Narrow memory access of compare to byte width ubizjak at gmail dot com
  2023-10-05  7:51 ` [Bug target/111698] " rguenth at gcc dot gnu.org
  2023-10-05 11:29 ` ubizjak at gmail dot com
@ 2023-10-24 12:12 ` ubizjak at gmail dot com
  2023-10-25 14:28 ` cvs-commit at gcc dot gnu.org
  2023-10-25 14:30 ` ubizjak at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2023-10-24 12:12 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ubizjak at gmail dot com
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-10-24

--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
Created attachment 56187
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56187&action=edit
Propsed patch

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

* [Bug target/111698] Narrow memory access of compare to byte width
  2023-10-04 20:52 [Bug target/111698] New: Narrow memory access of compare to byte width ubizjak at gmail dot com
                   ` (2 preceding siblings ...)
  2023-10-24 12:12 ` ubizjak at gmail dot com
@ 2023-10-25 14:28 ` cvs-commit at gcc dot gnu.org
  2023-10-25 14:30 ` ubizjak at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-25 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:678e6c328c77db383431751bcfcf867b02369bd6

commit r14-4928-g678e6c328c77db383431751bcfcf867b02369bd6
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Wed Oct 25 16:26:57 2023 +0200

    i386: Narrow test instructions with immediate operands [PR111698]

    Narrow test instructions with immediate operand that test memory location
    for zero.  E.g. testl $0x00aa0000, mem can be converted to testb $0xaa,
mem+2.
    Reject targets where reading (possibly unaligned) part of memory location
    after a large write to the same address causes store-to-load forwarding
stall.

            PR target/111698

    gcc/ChangeLog:

            * config/i386/x86-tune.def (X86_TUNE_PARTIAL_MEMORY_READ_STALL):
            New tune.
            * config/i386/i386.h (TARGET_PARTIAL_MEMORY_READ_STALL): New macro.
            * config/i386/i386.md: New peephole pattern to narrow test
            instructions with immediate operands that test memory locations
            for zero.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr111698.c: New test.

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

* [Bug target/111698] Narrow memory access of compare to byte width
  2023-10-04 20:52 [Bug target/111698] New: Narrow memory access of compare to byte width ubizjak at gmail dot com
                   ` (3 preceding siblings ...)
  2023-10-25 14:28 ` cvs-commit at gcc dot gnu.org
@ 2023-10-25 14:30 ` ubizjak at gmail dot com
  4 siblings, 0 replies; 6+ messages in thread
From: ubizjak at gmail dot com @ 2023-10-25 14:30 UTC (permalink / raw)
  To: gcc-bugs

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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|x86_64-*-*                  |x86-*-*
   Target Milestone|---                         |14.0
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Uroš Bizjak <ubizjak at gmail dot com> ---
Implemented for gcc-14.

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

end of thread, other threads:[~2023-10-25 14:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-04 20:52 [Bug target/111698] New: Narrow memory access of compare to byte width ubizjak at gmail dot com
2023-10-05  7:51 ` [Bug target/111698] " rguenth at gcc dot gnu.org
2023-10-05 11:29 ` ubizjak at gmail dot com
2023-10-24 12:12 ` ubizjak at gmail dot com
2023-10-25 14:28 ` cvs-commit at gcc dot gnu.org
2023-10-25 14:30 ` ubizjak 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).