* [x86 PATCH] Use ix86_expand_clear in ix86_split_ashl.
@ 2022-12-28 0:06 Roger Sayle
2022-12-28 9:02 ` Uros Bizjak
0 siblings, 1 reply; 2+ messages in thread
From: Roger Sayle @ 2022-12-28 0:06 UTC (permalink / raw)
To: 'GCC Patches'; +Cc: 'Uros Bizjak'
[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]
This patch is a one line change, to call ix86_expand_clear instead of
emit_move_insn with const0_rtx in ix86_split_ashl, allowing the backend
to use an xor instruction to clear a register if appropriate.
The effect is demonstrated with the following function.
__int128 foo(__int128 x, unsigned long long b) {
return ((__int128)b << 72) + x;
}
previously with -O2, GCC would generate
foo: movl $0, %eax
salq $8, %rdx
addq %rdi, %rax
adcq %rsi, %rdx
ret
with this patch, it now generates
foo: xorl %eax, %eax
salq $8, %rdx
addq %rdi, %rax
adcq %rsi, %rdx
ret
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. It's an independent piece of a larger bug fix.
Ok for mainline?
2022-12-28 Roger Sayle <roger@nextmovesoftware.com>
gcc/ChangeLog
* config/i386/i386-expand.cc (ix86_split_ashl): Call
ix86_expand_clear to generate an xor instruction.
gcc/testsuite/ChangeLog
* gcc.target/i386/ashlti3-1.c: New test case.
Thanks in advance,
Roger
--
[-- Attachment #2: patchzz.txt --]
[-- Type: text/plain, Size: 984 bytes --]
diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index b6cc76d..3eddbc9 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -6211,7 +6211,7 @@ ix86_split_ashl (rtx *operands, rtx scratch, machine_mode mode)
if (count >= half_width)
{
emit_move_insn (high[0], low[1]);
- emit_move_insn (low[0], const0_rtx);
+ ix86_expand_clear (low[0]);
if (count > half_width)
ix86_expand_ashl_const (high[0], count - half_width, mode);
diff --git a/gcc/testsuite/gcc.target/i386/ashlti3-1.c b/gcc/testsuite/gcc.target/i386/ashlti3-1.c
new file mode 100644
index 0000000..1cf1306
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/ashlti3-1.c
@@ -0,0 +1,6 @@
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2" } */
+__int128 foo(__int128 x, unsigned long long b) {
+ return ((__int128)b << 72) + x;
+}
+/* { dg-final { scan-assembler-not "\tmovl\[ \\t\]+\\\$0," } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [x86 PATCH] Use ix86_expand_clear in ix86_split_ashl.
2022-12-28 0:06 [x86 PATCH] Use ix86_expand_clear in ix86_split_ashl Roger Sayle
@ 2022-12-28 9:02 ` Uros Bizjak
0 siblings, 0 replies; 2+ messages in thread
From: Uros Bizjak @ 2022-12-28 9:02 UTC (permalink / raw)
To: Roger Sayle; +Cc: GCC Patches
On Wed, Dec 28, 2022 at 1:06 AM Roger Sayle <roger@nextmovesoftware.com> wrote:
>
> This patch is a one line change, to call ix86_expand_clear instead of
> emit_move_insn with const0_rtx in ix86_split_ashl, allowing the backend
> to use an xor instruction to clear a register if appropriate.
>
> The effect is demonstrated with the following function.
> __int128 foo(__int128 x, unsigned long long b) {
> return ((__int128)b << 72) + x;
> }
>
> previously with -O2, GCC would generate
>
> foo: movl $0, %eax
> salq $8, %rdx
> addq %rdi, %rax
> adcq %rsi, %rdx
> ret
>
> with this patch, it now generates
>
> foo: xorl %eax, %eax
> salq $8, %rdx
> addq %rdi, %rax
> adcq %rsi, %rdx
> ret
>
> 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. It's an independent piece of a larger bug fix.
> Ok for mainline?
>
>
> 2022-12-28 Roger Sayle <roger@nextmovesoftware.com>
>
> gcc/ChangeLog
> * config/i386/i386-expand.cc (ix86_split_ashl): Call
> ix86_expand_clear to generate an xor instruction.
>
> gcc/testsuite/ChangeLog
> * gcc.target/i386/ashlti3-1.c: New test case.
OK.
Thanks,
Uros.
>
>
> Thanks in advance,
> Roger
> --
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-28 9:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-28 0:06 [x86 PATCH] Use ix86_expand_clear in ix86_split_ashl Roger Sayle
2022-12-28 9:02 ` Uros Bizjak
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).