[Bug target/85730] complex code for modifying lowest byte in a 4-byte vector

ubizjak at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 8 09:36:46 GMT 2021


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

--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> ---
An interesting observation with the following testcase:

--cut here--
typedef char V __attribute__((vector_size(4)));

struct S
{
  char val;
  char pad1;
  char pad2;
  char pad3;
};

V
foo (V v)
{
  v[0] <<= 3;

  return v;
}

struct S
bar (struct S a)
{
  a.val <<= 3;

  return a;
}
--cut here--

gcc -O2:

foo:
        movsbl  %dil, %edx
        movl    %edi, %eax
        sall    $3, %edx
        movb    %dl, %al
        ret

bar:
        movl    %edi, %eax
        salb    $3, %al
        ret

So, the compiler is able to produce optimal code with equivalent struct
description, but something (in middle-end?) prevents the same optimization with
a vector (a.k.a array).


More information about the Gcc-bugs mailing list