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:53:31 -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> <CABXYE2W1ZjAYn2V5cADG5Mp-EvGhY3+i8d21PtagYob5nvnKaw at mail dot gmail dot com>
On Sun, Jan 31, 2016 at 8:43 PM, Jim Wilson <jim.wilson@linaro.org> wrote:
>> 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.
If there is a div insn, then yes, gcc will emit a div and a multiply.
However, a div insn is a relatively recent addition to the 32-bit ARM
architecture. Without the div insn, we get a div libcall and a mod
libcall. That means two libcalls, both of which are likely
implemented by calling the divmod libcall and returning the desired
part of the result. One call to a divmod libcall is clearly more
efficient than two calls to a divmod libcall. So that makes the
transformation useful.
Prathamesh's patch has a number of conditions required to trigger the
optimization, such as a divmod insn, or a lack of a div insn and the
presence of a divmod libcall.
Jim