[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Bug target/11877] gcc should use xor trick with -Os



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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:d58a66aa0faa64bfbd85e528be5104293dd41d0e

commit r12-1712-gd58a66aa0faa64bfbd85e528be5104293dd41d0e
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Jun 22 10:16:18 2021 +0200

    i386: Use xor to write zero to memory with -Os even for more than 4 stores
[PR11877]

    > > 2021-06-20  Roger Sayle  <roger@nextmovesoftware.com>
    > >
    > > gcc/ChangeLog
    > >         PR target/11877
    > >         * config/i386/i386.md: New define_peephole2s to shrink writing
    > >         1, 2 or 4 consecutive zeros to memory when optimizing for size.

    It unfortunately doesn't extend well to larger memory clearing.
    Consider e.g.
    void
    foo (int *p)
    {
      p[0] = 0;
      p[7] = 0;
      p[23] = 0;
      p[41] = 0;
      p[48] = 0;
      p[59] = 0;
      p[69] = 0;
      p[78] = 0;
      p[83] = 0;
      p[89] = 0;
      p[98] = 0;
      p[121] = 0;
      p[132] = 0;
      p[143] = 0;
      p[154] = 0;
    }
    where with the patch we emit:
            xorl    %eax, %eax
            xorl    %edx, %edx
            xorl    %ecx, %ecx
            xorl    %esi, %esi
            xorl    %r8d, %r8d
            movl    %eax, (%rdi)
            movl    %eax, 28(%rdi)
            movl    %eax, 92(%rdi)
            movl    %eax, 164(%rdi)
            movl    %edx, 192(%rdi)
            movl    %edx, 236(%rdi)
            movl    %edx, 276(%rdi)
            movl    %edx, 312(%rdi)
            movl    %ecx, 332(%rdi)
            movl    %ecx, 356(%rdi)
            movl    %ecx, 392(%rdi)
            movl    %ecx, 484(%rdi)
            movl    %esi, 528(%rdi)
            movl    %esi, 572(%rdi)
            movl    %r8d, 616(%rdi)
    Here is an incremental patch that emits:
            xorl    %eax, %eax
            movl    %eax, (%rdi)
            movl    %eax, 28(%rdi)
            movl    %eax, 92(%rdi)
            movl    %eax, 164(%rdi)
            movl    %eax, 192(%rdi)
            movl    %eax, 236(%rdi)
            movl    %eax, 276(%rdi)
            movl    %eax, 312(%rdi)
            movl    %eax, 332(%rdi)
            movl    %eax, 356(%rdi)
            movl    %eax, 392(%rdi)
            movl    %eax, 484(%rdi)
            movl    %eax, 528(%rdi)
            movl    %eax, 572(%rdi)
            movl    %eax, 616(%rdi)
    instead.

    2021-06-22  Jakub Jelinek  <jakub@redhat.com>

            PR target/11877
            * config/i386/i386-protos.h (ix86_last_zero_store_uid): Declare.
            * config/i386/i386-expand.c (ix86_last_zero_store_uid): New
variable.
            * config/i386/i386.c (ix86_expand_prologue): Clear it.
            * config/i386/i386.md (peephole2s for 1/2/4 stores of const0_rtx):
            Remove "" from match_operand.  Emit new insns using emit_move_insn
and
            set ix86_last_zero_store_uid to INSN_UID of the last store.
            Add peephole2s for 1/2/4 stores of const0_rtx following previous
            successful peep2s.

            * gcc.target/i386/pr11877-2.c: New test.

-- 
You are receiving this mail because:
You reported the bug.

Reply to: