aboutsummaryrefslogtreecommitdiff
path: root/gcc/range-op.cc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2021-08-17 10:50:56 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-08-17 11:39:15 +0200
commit891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6 (patch)
treec93c4b18b2ba3f502656545506092147ff369ec8 /gcc/range-op.cc
parent3ed779689631ff8f398dcde06d5efa2a3c43ef27 (diff)
downloadgcc-891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6.zip
gcc-891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6.tar.gz
gcc-891bdbf2b0432b4aa3d3e76923617fcb4fd33cf6.tar.bz2
Special case -TYPE_MIN_VALUE for flag_wrapv in operator_abs::op1_range.
With flag_wrapv, -TYPE_MIN_VALUE = TYPE_MIN_VALUE which is unrepresentable. We currently special case this in the ABS folding routine, but are missing similar treatment in operator_abs::op1_range. Tested on x86-64 Linux. PR tree-optimization/101938 gcc/ChangeLog: * range-op.cc (operator_abs::op1_range): Special case -TYPE_MIN_VALUE for flag_wrapv. gcc/testsuite/ChangeLog: * gcc.dg/pr101938.c: New test.
Diffstat (limited to 'gcc/range-op.cc')
-rw-r--r--gcc/range-op.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index eb66e12..56eccf4 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -3642,6 +3642,12 @@ operator_abs::op1_range (irange &r, tree type,
r.union_ (int_range<1> (type,
-positives.upper_bound (i),
-positives.lower_bound (i)));
+ // With flag_wrapv, -TYPE_MIN_VALUE = TYPE_MIN_VALUE which is
+ // unrepresentable. Add -TYPE_MIN_VALUE in this case.
+ wide_int min_value = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
+ wide_int lb = lhs.lower_bound ();
+ if (!TYPE_OVERFLOW_UNDEFINED (type) && wi::eq_p (lb, min_value))
+ r.union_ (int_range<2> (type, lb, lb));
return true;
}