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

            Bug ID: 111657
           Summary: Memory copy with structure assignment from named
                    address space is not working
           Product: gcc
           Version: 12.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

Taken from [1]. Compile the following testcase with -O2 -mno-sse:

--cut here--
struct a
{
  long arr[30];
};

__seg_gs struct a m;

void
foo (struct a *dst)
{
  *dst = m;
}
--cut here--

the produced assembly:

foo:
.LFB0:
        xorl    %eax, %eax
        cmpq    $240, %rax
        jnb     .L5
.L2:
        movzbl  %gs:m(%rax), %edx
        movb    %dl, (%rdi,%rax)
        addq    $1, %rax
        cmpq    $240, %rax
        jb      .L2
.L5:
        ret

As rightfully said in [1]:

"...and look at the end result. It's complete and utter sh*t:

<...>

to the point that I can only go "WTF"?

I mean, it's not just that it does the copy one byte at a time. It
literally compares %rax to $240 just after it has cleared it. I look
at that code, and I go "a five-year old with a crayon could have done
better".

[1]
https://lore.kernel.org/lkml/CAHk-=wh+cfn58xxmlng6dh+eb9-2dyfabxjf2ftsz+vfqvv...@mail.gmail.com/

Reply via email to