On Mon, 1 Dec 2014, Richard Biener wrote:

> +/* Combine two successive divisions.  */
> +(for div (trunc_div ceil_div floor_div round_div exact_div)

This doesn't seem correct for all kinds of division and signedness of 
arguments.

TRUNC_DIV_EXPR (C division) and EXACT_DIV_EXPR should be OK regardless.  
But for CEIL_DIV_EXPR and FLOOR_DIV_EXPR, in ((a / b) / c) you need c to 
be positive so that both roundings are in the same direction (consider 
e.g. 3 FLOOR_DIV -2 FLOOR_DIV -2 == 1, but 3 FLOOR_DIV 4 == 0).  And for 
ROUND_DIV_EXPR, it can be incorrect whatever the signs (e.g. 2 ROUND_DIV 3 
ROUND_DIV 2 == 1, but 2 ROUND_DIV 6 == 0).

I'm not sure if these forms of division actually occur in places where 
this could cause a problem, but it does look like Ada may enable you to 
generate ROUND_DIV_EXPR.

-- 
Joseph S. Myers
jos...@codesourcery.com

Reply via email to