Richard Sandiford wrote: > 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.
Sure you can always make up a contrived example where one case is better than another. In many cases it's just going to be a heuristic. With division the best option is far more obvious than in most cases. > 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. Every single decision a compiler makes cannot be optimal for all cases - what matters is what is best on average in real code. Wilco