public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/101366] New: x86 memset codegen for constant sized is suboptimal
@ 2021-07-07 14:21 kutdanila at yandex dot ru
  2021-07-07 20:13 ` [Bug target/101366] memset codegen for constant sized does not use SSE instructions pinskia at gcc dot gnu.org
  2021-07-08 13:03 ` hjl.tools at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: kutdanila at yandex dot ru @ 2021-07-07 14:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101366
           Summary: x86 memset codegen for constant sized is suboptimal
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kutdanila at yandex dot ru
  Target Milestone: ---

https://gcc.godbolt.org/z/hP99MYMEG

void Test(char* dst) {
    __m128i pattern = _mm_set1_epi8(dst[-1]);
    for (int i = 0; i < 4; i++) {
        _mm_loadu_si128(reinterpret_cast<__m128i*>(dst + 16 * i), pattern);
    }
}

vs

void TestStd(char* s) {
    memset(s, s[-1], 64);
}


-O3 -msse4.2

Test(char*):
        movzbl  -1(%rdi), %eax
        pxor    %xmm1, %xmm1
        movd    %eax, %xmm0
        pshufb  %xmm1, %xmm0
        movups  %xmm0, (%rdi)
        movups  %xmm0, 16(%rdi)
        movups  %xmm0, 32(%rdi)
        movups  %xmm0, 48(%rdi)
        ret
TestStd(char*):
        movabsq $72340172838076673, %rdx
        movzbl  -1(%rdi), %eax
        movq    %rax, %rcx
        imulq   %rdx, %rcx
        mulq    %rdx
        addq    %rcx, %rdx
        movq    %rax, (%rdi)
        movq    %rdx, 8(%rdi)
        movq    %rax, 16(%rdi)
        movq    %rdx, 24(%rdi)
        movq    %rax, 32(%rdi)
        movq    %rdx, 40(%rdi)
        movq    %rax, 48(%rdi)
        movq    %rdx, 56(%rdi)
        ret

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

end of thread, other threads:[~2021-07-08 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-07 14:21 [Bug rtl-optimization/101366] New: x86 memset codegen for constant sized is suboptimal kutdanila at yandex dot ru
2021-07-07 20:13 ` [Bug target/101366] memset codegen for constant sized does not use SSE instructions pinskia at gcc dot gnu.org
2021-07-08 13:03 ` hjl.tools 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).