This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: divmod pattern question
- From: Jeff Law <law at redhat dot com>
- To: Paul Koning <paulkoning at comcast dot net>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Tue, 19 Jun 2018 23:16:35 -0600
- Subject: Re: divmod pattern question
- References: <65296BEC-0850-41E8-A5D0-FC8FFA4C17E5@comcast.net>
On 06/19/2018 12:55 PM, Paul Koning wrote:
> Gentlepeople,
>
> I have a two-operand divide instruction that takes a double length dividend in a register pair, and produces the quotient in the first register and remainder in the second.
>
> How do I write a divmod pattern for that? The quotient is easy enough, I write a match_operand for that register and a matching constraint ("0") for the input dividend. But what about the remainder? The remainder appears in a register that isn't explicitly mentioned in the RTL (it's the regnum one higher than the quotient, or if you like, the second subreg of the input (dividend) register.
You can generally allocate double-sized registers with appropriate
constraints and the like. And you could use matching constraints,
perhaps with subregs, but in the end, ewwwww.
>
> I can make it a define_expand that adds a move from the remainder register into a new register which is the output operand, and count on the optimizer to optimize away that move. Is that the best answer? The current "mod" pattern does that, and I could keep that approach.
But this would generally be better I think. I'd expect the move to be
optimized away the vast majority of the time.
jeff