On Thu, Jun 27, 2024 at 9:40 PM Roger Sayle <ro...@nextmovesoftware.com> wrote:
>
>
> This patch generalizes some of the patterns in i386.md that recognize
> double word concatenation, so they handle sign_extend the same way that
> they handle zero_extend in appropriate contexts.
>
> As a motivating example consider the following function:
>
> __int128 foo(long long x, unsigned long long y)
> {
>   return ((__int128)x<<64) | y;
> }
>
> when compiled with -O2, x86_64 currently generates:
>
> foo:    movq    %rdi, %rdx
>         xorl    %eax, %eax
>         xorl    %edi, %edi
>         orq     %rsi, %rax
>         orq     %rdi, %rdx
>         ret
>
> with this patch we now generate (the same as if x is unsigned):
>
> foo:    movq    %rsi, %rax
>         movq    %rdi, %rdx
>         ret
>
> Treating both extensions the same way using any_extend is valid as
> the top (extended) bits are "unused" after the shift by 64 (or more).
> In theory, the RTL optimizers might consider canonicalizing the form
> of extension used in these cases, but zero_extend is faster on some
> machines, whereas sign extension is supported via addressing modes on
> others, so handling both in the machine description is probably best.
>
> This patch has been tested on x86_64-pc-linux-gnu with make bootstrap
> and make -k check, both with and without --target_board=unix{-m32}
> with no new failures.  Ok for mainline?
>
>
> 2024-06-27  Roger Sayle  <ro...@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * config/i386/i386.md (*concat<mode><dwi>3_3): Change zero_extend
>         to any_extend in first operand to left shift by mode precision.
>         (*concat<mode><dwi>3_4): Likewise.
>         (*concat<mode><dwi>3_6): Likewise.
>
> gcc/testsuite/ChangeLog
>         * gcc.target/i386/concatditi-1.c: New test case.

OK.

Thanks,
Uros.

>
>
> Thanks in advance,
> Roger
> --
>

Reply via email to