Improve overflow check
authorJeff Law <law@redhat.com>
Fri, 6 Nov 2020 03:42:17 +0000 (20:42 -0700)
committerJeff Law <law@redhat.com>
Fri, 6 Nov 2020 03:46:00 +0000 (20:46 -0700)
commit32ee472864ada44ef05b2a3b087b8ce413bee282
tree058c571d79ef476500b22795e764f3cce62c755d
parent6483f05989ef31ebf2583deeb4753211ca2b7e17
Improve overflow check

Convert
x < (short) ((unsigned short)x + const)
to
x <= SHORT_MAX – const
(and similarly for other integral types) if const is not 0.

gcc/
PR tree-optimization/97223
* match.pd (overflow detection and optimization): Handle conversions.

gcc/testsuite/

* gcc.dg/no-strict-overflow-4.c: Adjust expected output.
gcc/match.pd
gcc/testsuite/gcc.dg/no-strict-overflow-4.c