This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Transform (x / y) != 0 to x >=y and (x / y) == 0 to x < y if x, y are unsigned
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: "marc dot glisse at inria dot fr" <marc dot glisse at inria dot fr>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: nd <nd at arm dot com>, Jeff Law <law at redhat dot com>, "prathamesh dot kulkarni at linaro dot org" <prathamesh dot kulkarni at linaro dot org>, "Richard Biener" <richard dot guenther at gmail dot com>
- Date: Fri, 15 Sep 2017 16:14:42 +0000
- Subject: Re: Transform (x / y) != 0 to x >=y and (x / y) == 0 to x < y if x, y are unsigned
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
Marc Glisse wrote:
> The question is whether, having computed c=a/b, it is cheaper to test a<b or c!=0.
> I think it is usually the second one, but not for all types on all targets. Although since
> you mention VRP, it is easier to do further optimizations using the information a<b.
No, a<b is always better. Division does have high latency and low throughput on
all modern cores, so rather than having to wait until the division finishes, you can
execute whatever depends on the comparison many cycles earlier.
Generally you want to avoid division as much as possible and when that fails
reduce any dependencies on the result of divisions.
Wilco