On Mon, 26 Feb 2024, Jakub Jelinek wrote:

> On Mon, Feb 26, 2024 at 03:15:02PM +0100, Richard Biener wrote:
> > When folding a multiply CHRECs are handled like {a, +, b} * c
> > is {a*c, +, b*c} but that isn't generally correct when overflow
> > invokes undefined behavior.  The following uses unsigned arithmetic
> > unless either a is zero or a and b have the same sign.
> > 
> > I've used simple early outs for INTEGER_CSTs and otherwise use
> > a range-query since we lack a tree_expr_nonpositive_p.
> 
> What about testing
>     (get_range_pos_neg (CHREC_LEFT (op0))
>      | get_range_pos_neg (CHREC_RIGHT (op0))) != 3
> ?

Ah, didn't know about that.  It seems to treat zero as "always
positive", so for 0 and -1 I'd get 3.  OK as I check for
zero CHREC_LEFT separately.

I'll note that get_range_pos_neg only asks global range query
and for SSA names (but not sure if range_of_expr handles aribitrary
GENERIC as SCEV tends to have here ...).

Will update the patch, I think any improvement should be done
to get_range_pos_neg (it's a bit odd in behavior for unsigned
but I have only signed things incoming).

Richard.

Reply via email to