On Tue, Apr 29, 2025 at 5:52 PM Uros Bizjak <ubiz...@gmail.com> wrote: > > MOVS instructions allow segment override of their source operand, e.g.: > > rep movsq %gs:(%rsi), (%rdi) > > where %rsi is the address of the source location (with %gs segment override) > and %rdi is the address of the destination location.
Please be aware that 0x67 prefix (used by x32) is applied before segment register. That is in rep movsq %gs:(%esi), (%edi) the address is %gs + %esi. > The testcase improves from (-O2 -mno-sse -mtune=generic): > > xorl %eax, %eax > .L2: > movl %eax, %edx > addl $8, %eax > movq %gs:m(%rdx), %rcx > movq %rcx, (%rdi,%rdx) > cmpl $240, %eax > jb .L2 > ret > > to: > movl $m, %esi > movl $30, %ecx > rep movsq %gs:(%rsi), (%rdi) > ret > > PR 111657 > > gcc/ChangeLog: > > * config/i386/i386-expand.cc (alg_usable_p): Remove have_as bool > argument and add dst_as and src_as address space arguments. Reject > libcall algorithm with dst_as and src_as in the non-default address > spaces. Reject rep_prefix_{1,4,8}_byte algorithms with dst_as in > the non-default address space. > (decide_alg): Remove have_as bool argument and add dst_as and src_as > address space arguments. Update calls to alg_usable_p. > (ix86_expand_set_or_cpymem): Update call to decide_alg. > * config/i386/i386.md (strmov): Do not fail if operand[3] (source) > is in the non-default address space. Expand with gen_strmov_singleop > only when operand[1] (destination) is in the default address space. > (*strmovdi_rex_1): Determine memory operands from insn pattern. > Allow only when destination is in the default address space. > Rewrite asm template to use explicit operands. > (*strmovsi_1): Ditto. > (*strmovhi_1): DItto. > (*strmovqi_1): Ditto. > (*rep_movdi_rex64): Ditto. > (*rep_movsi): Ditto. > (*rep_movqi): Ditto. > (*strsetdi_rex_1): Determine memory operands from insn pattern. > Allow only when destination is in the default address space. > (*strsetsi_1): Ditto. > (*strsethi_1): Ditto. > (*strsetqi_1): Ditto. > (*rep_stosdi_rex64): Ditto. > (*rep_stossi): Ditto. > (*rep_stosqi): Ditto. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/pr111657-1.c: New test. > > Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. > > Uros. -- H.J.