On Fri, Dec 10, 2021 at 12:58 PM Roger Sayle <ro...@nextmovesoftware.com> wrote: > > > While working on a middle-end patch to more aggressively use highpart > multiplications on targets that support them, I noticed that the RTL > expanded by the x86 backend interacts poorly with register allocation > leading to suboptimal code. > > For the testcase, > typedef int __attribute ((mode(TI))) ti_t; > long foo(long x) > { > return ((ti_t)x * 19065) >> 64; > } > > we'd like to avoid: > foo: movq %rdi, %rax > movl $19065, %edx > imulq %rdx > movq %rdx, %rax > ret > > and would prefer: > foo: movl $19065, %eax > imulq %rdi > movq %rdx, %rax > ret > > This patch provides a pair of peephole2 transformations to tweak the > spills generated by reload, and at the same time replaces the current > define_expand with define_insn patterns using the new [su]mul_highpart > RTX codes. I've left the old-style patterns in the machine description > for the time being, but plan to remove these once my planned middle-end > improvements make them obsolete. > > This patch has been tested on x86_64-pc-linux-gnu (both with and without > the middle-end changes) by make bootstrap and make -k check with no new > failures. The new test case, which currently passes, ensures that the > code we generate isn't adversely affected by changes outside the backend. > Ok for mainline? > > > 2021-12-10 Roger Sayle <ro...@nextmovesoftware.com> > > gcc/ChangeLog > * config/i386/i386.md (any_mul_highpart): New code iterator. > (sgnprefix, s): Add attribute support for [su]mul_highpart. > (<s>mul<mode>3_highpart): Delete expander. > (<s>muldi3_highpart, <s>mulsi3_highpart, <s>mulsi32_highpart_zext): > New define_insn patterns. > (define_peephole2): Tweak the register allocation for the above > instructions after reload. > > gcc/testsuite/ChangeLog > * gcc.target/i386/smuldi3_highpart.c: New test case.
Can you please merge <s>muldi3_highpart and *<s>mulsi3_highpart using SWI48 mode iterator? Uros. > > > Thanks in advance, > Roger > -- >