Wilco Dijkstra <wilco.dijks...@arm.com> writes: > 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.
I don't think it's literally always. Testing the inputs instead of a multi-use result tends to mean that all three are live at once. If the == 0 condition is only one component of a more complex condition that relies on the result of division regardless, then it's possible for testing the inputs to be a pessimisation, particularly on two-address targets. Not saying that's a strong enough reason not to do it. I just don't think that we can guarantee it will be better in *every* case. Thanks, Richard