This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [RFC PR43721] Optimize a/b and a%b to single divmod call
- From: Jim Wilson <jim dot wilson at linaro dot org>
- To: Richard Henderson <rth at redhat dot com>
- Cc: Richard Biener <rguenther at suse dot de>, Prathamesh Kulkarni <prathamesh dot kulkarni at linaro dot org>, Kugan Vivekanandarajah <kugan dot vivekanandarajah at linaro dot org>, Ramana Radhakrishnan <ramana dot radhakrishnan at arm dot com>, "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, richard dot sandiford at arm dot com
- Date: Sun, 31 Jan 2016 20:43:33 -0800
- Subject: Re: [RFC PR43721] Optimize a/b and a%b to single divmod call
- Authentication-results: sourceware.org; auth=none
- References: <CAAgBjMmSzFUwa8W2Tc6GzGcA3nTZ_7oOfyB-UPmRLtfKXioUMQ at mail dot gmail dot com> <CAFiYyc1OVk2L76pTjhRFzgco-D7YbA=uK+xG95Xn-whuFh292Q at mail dot gmail dot com> <CAAgBjM=XtqUa60TOdRXnpMkMcGO7fAupbuYWGmTPbt_qkkOrgQ at mail dot gmail dot com> <CAAgBjMmF4kUK2Uovw=rxYF1vpjAmfzFTsXQaRj9yj7v+ep1-Ag at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1511021342240 dot 10078 at zhemvz dot fhfr dot qr> <CAAgBjMmB=ow24szF+qW01+ordKGcOEHRLcx5fLyQnzvHND0fow at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1511041546420 dot 10078 at zhemvz dot fhfr dot qr> <CAAgBjMnL__ZhkLZG=kOL3xrf-s6gGvW6EGBvqeizrE0WDdQ8Zg at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1511101522180 dot 10078 at zhemvz dot fhfr dot qr> <CAAgBjM=9Uu_=SQp+v6nM3xK_7Eg6AFcDTfVO2EQP_Z_vUeg93g at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1511111127310 dot 4884 at t29 dot fhfr dot qr> <CAAgBjMn2MtfChCkk0ZQ-n10t_gzHviUBu+NDZNfLNFBmT35xAw at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1511111429220 dot 4884 at t29 dot fhfr dot qr> <CAAgBjM=FZEoU2c+OAnunCx4teZdBXOxAwyf5V3BFSD1PL08vUg at mail dot gmail dot com> <alpine dot LSU dot 2 dot 11 dot 1601281434470 dot 31122 at t29 dot fhfr dot qr> <56AE878C dot 5060704 at redhat dot com>
On Sun, Jan 31, 2016 at 2:15 PM, Richard Henderson <rth@redhat.com> wrote:
> On 01/29/2016 12:37 AM, Richard Biener wrote:
>>>
>>> To workaround this, I defined a new hook expand_divmod_libfunc, which
>>> targets must override for expanding call to target-specific dimovd.
>>> The "default" hook default_expand_divmod_libfunc() expands call to
>>> libgcc2.c:__udivmoddi4() since that's the only "generic" divmod
>>> available.
>>> Is this a reasonable approach ?
>>
>>
>> Hum. How do they get to expand/generate it today? That said, I'm
>> no expert in this area.
>>
>> A simpler solution may be to not do the transform if there is no
>> instruction for divmod.
>
>
> Are we certain that the libcall is a win for any target?
>
> I would have expected a default of
>
> q = x / y
> r = x - (q * y)
>
> to be most efficient on modern machines. Even more so on targets like ARM
> that have multiply-and-subtract instructions.
>
> I suppose there's the case of the really tiny embedded chips that don't have
> multiply patterns either. So that this default expansion still results in
> multiple libcalls.
>
> I do like the transformation, because for machines that don't have a divmod
> instruction, being able to strength-reduce a mod operation to a multiply
> operation is a nice win.
>
>
> r~