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

--- Comment #32 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to rguent...@suse.de from comment #20)

> Index: gcc/tree-ssa-sccvn.c
> ===================================================================
> --- gcc/tree-ssa-sccvn.c        (revision 254945)
> +++ gcc/tree-ssa-sccvn.c        (working copy)
> @@ -3632,6 +3632,38 @@ visit_nary_op (tree lhs, gassign *stmt)

The patched compiler works for this particular case (a "break" is needed at the
top of the patch, though), but there are many other cases where a temporary
should be calculated and its value stored, e.g.:

--cut here--
void foo_OK (char *buf, unsigned int data)
{
  buf[0] = ~data >> 8;
  buf[1] = ~data;
}

void foo (char *buf, unsigned int data)
{
  buf[0] = ~data;
  buf[1] = ~data >> 8;
}

void bar (char *buf, unsigned int data)
{
  buf[0] = -data >> 8;
  buf[1] = -data;
}

void baz (char *buf, unsigned int data)
{
  buf[0] = (data+3) >> 8;
  buf[1] = (data+3);
}
--cut here--

Only foo_OK compiles (-O2 -march=haswell) to expected asm:

        notl    %esi
        movbe   %si, (%rdi)

all others generate duplicated operation:

        movb    %sil, %al
        notl    %esi
        notl    %eax
        movb    %al, (%rdi)
        movl    %esi, %eax
        movb    %ah, 1(%rdi)

Should I open a new PR for the above enhancement?

Reply via email to