public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96938] New: Failure to optimize bit-setting pattern when not using temporary
@ 2020-09-04 14:10 gabravier at gmail dot com
  2020-09-04 16:31 ` [Bug tree-optimization/96938] " glisse at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: gabravier at gmail dot com @ 2020-09-04 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96938
           Summary: Failure to optimize bit-setting pattern when not using
                    temporary
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

void g(char *f, int offset, char value)
{
        *f = (int)(*f & ~(1 << (offset & 0x1F))) | (value << (offset & 0x1F));
}

This has much worse code generation than this:

void g(char *f, int offset, char value)
{
        int tmp = *f & ~(1 << (offset & 0x1F));
        *f = tmp | (value << (offset & 0x1F));
}

Which should be equivalent to the first example.

Example of the worse code generation, on x86 the first example compiles to
this:

g(char*, int, char):
  movzx ecx, BYTE PTR [rdi]
  mov eax, 1
  movsx edx, dl
  shlx eax, eax, esi
  shlx edx, edx, esi
  andn eax, eax, ecx
  or eax, edx
  mov BYTE PTR [rdi], al
  ret

Whereas the second example compiles to this:

g(char*, int, char):
  movsx eax, BYTE PTR [rdi]
  movsx edx, dl
  shlx edx, edx, esi
  btr eax, esi
  or eax, edx
  mov BYTE PTR [rdi], al
  ret

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

end of thread, other threads:[~2021-01-13  9:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04 14:10 [Bug tree-optimization/96938] New: Failure to optimize bit-setting pattern when not using temporary gabravier at gmail dot com
2020-09-04 16:31 ` [Bug tree-optimization/96938] " glisse at gcc dot gnu.org
2021-01-12 16:22 ` jakub at gcc dot gnu.org
2021-01-12 16:42 ` jakub at gcc dot gnu.org
2021-01-12 18:17 ` jakub at gcc dot gnu.org
2021-01-13  9:16 ` cvs-commit at gcc dot gnu.org
2021-01-13  9:25 ` jakub 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).