On 04/19/2017 08:59 AM, Eric Botcazou wrote:
I know this attempts to be a copy of what is used elsewhere, but
at least there it is a result of wi::sub etc.
Wouldn't it be simpler to
if (sgn == SIGNED && wi::neg_p (min_op1) && wi::neg_p (wmin))
min_ovf = 1;
else if (sgn == UNSIGNED && wi::ne_p (min_op1, 0))
min_ovf = -1;
I mean, for SIGNED if min_op1 is 0, then wmin is 0 to and we want
min_ovf = 0;
If it is positive, wmin will be surely negative and again we want
min_ovf = 0. Only if it is negative and its negation is negative
too we want min_ovf = 1 (i.e. wi::cmps (0, most_negative) result).
For UNSIGNED, if min_op1 is 0, again all 3 wi::cmp will yield
0 and min_ovf = 0. If it is non-zero, it is > 0, therefore it
the first wi::cmp will return -1, the second wi::cmp returns
1 and the third one -1.
Fine with me.
Is that what we want (e.g. the UNSIGNED case to overflow pretty much always
except for 0 which should be optimized away anyway)?
I think so, you'd better be very cautious with overflow and symbolic ranges.
Or, shouldn't we just set if (!min_op0 && min_op1 && minus_p) min_op0 =
build_int_cst (expr_type, 0); before the if (min_op0 && min_op1) case
and don't duplicate that?
This isn't better than my version IMO.
Tested on x86_64-suse-linux, OK for mainline and 6 branch?
2017-04-19 Eric Botcazou <ebotca...@adacore.com>
Jakub Jelinek <ja...@redhat.com>
PR tree-optimization/80426
* tree-vrp.c (extract_range_from_binary_expr_1): For an additive
operation on symbolic operands, also compute the overflow for the
invariant part when the operation degenerates into a negation.
Jakub ACKd and I'm going to go ahead and install. I'll pull the
testsuite bits from a prior version.
Thanks,
Jeff