PR tree-optimization/98335: New peephole2 xorl;movb -> movzbl
authorRoger Sayle <roger@nextmovesoftware.com>
Fri, 11 Mar 2022 17:57:12 +0000 (17:57 +0000)
committerRoger Sayle <roger@nextmovesoftware.com>
Fri, 11 Mar 2022 17:57:12 +0000 (17:57 +0000)
commit251ea6dfbdb4448875e41081682bb3aa451b5729
tree1297567f040ce10d1d026251a788f7abf62e896f
parentc5288df751f9ecd11898dec5f2a7b6b03267f79e
PR tree-optimization/98335: New peephole2 xorl;movb -> movzbl

This patch is the backend piece of my proposed fix to PR tree-opt/98335,
to allow C++ partial struct initialization to be as efficient/optimized
as full struct initialization.

With the middle-end patch just posted to gcc-patches, the test case
in the PR compiles on x86_64-pc-linux-gnu with -O2 to:

        xorl    %eax, %eax
        movb    c(%rip), %al
        ret

with this additional peephole2 (actually four peephole2s):

        movzbl  c(%rip), %eax
        ret

2022-03-11  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
PR tree-optimization/98335
* config/i386/i386.md (peephole2): Eliminate redundant insv.
Combine movl followed by movb.  Transform xorl followed by
a suitable movb or movw into the equivalent movz[bw]l.

gcc/testsuite/ChangeLog
PR tree-optimization/98335
* g++.target/i386/pr98335.C: New test case.
* gcc.target/i386/pr98335.c: New test case.
gcc/config/i386/i386.md
gcc/testsuite/g++.target/i386/pr98335.C [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr98335.c [new file with mode: 0644]