Handle signed 1-bit ranges in irange::invert.
authorAldy Hernandez <aldyh@redhat.com>
Mon, 26 Oct 2020 16:50:37 +0000 (17:50 +0100)
committerAldy Hernandez <aldyh@redhat.com>
Mon, 26 Oct 2020 18:05:53 +0000 (19:05 +0100)
commit2118438f49f0c193abe3fa3def350a8129045746
tree9a14a7334ad2760d8c7ccbdb4de9220544e1c068
parentf20a6c57f0f26d9c60d6d6182f1e2181f727c834
Handle signed 1-bit ranges in irange::invert.

The problem here is we are trying to add 1 to a -1 in a signed 1-bit
field and coming up with UNDEFINED because of the overflow.

Signed 1-bits are annoying because you can't really add or subtract
one, because the one is unrepresentable.  For invert() we have a
special subtract_one() function that handles 1-bit signed fields.

This patch implements the analogous add_one() function so that invert
works.

gcc/ChangeLog:

PR tree-optimization/97555
* range-op.cc (range_tests): Test 1-bit signed invert.
* value-range.cc (subtract_one): Adjust comment.
(add_one): New.
(irange::invert): Call add_one.

gcc/testsuite/ChangeLog:

* gcc.dg/pr97555.c: New test.
gcc/range-op.cc
gcc/testsuite/gcc.dg/pr97555.c [new file with mode: 0644]
gcc/value-range.cc