widening_mul: pattern recognize further forms of __builtin_add_overflow [PR95853]
authorJakub Jelinek <jakub@redhat.com>
Sun, 22 Nov 2020 18:16:34 +0000 (19:16 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sun, 22 Nov 2020 18:16:34 +0000 (19:16 +0100)
commitc1fb592f2c3c6b5a6616cf882ce24d30e167a646
tree7539e06c8f43bcec10850ed0c4dbe2d01819b8aa
parentfdd2fb172940c5fc60e1d8195b30f7ebc0e754d0
widening_mul: pattern recognize further forms of __builtin_add_overflow [PR95853]

The following patch recognizes some further forms of additions with overflow
checks as shown in the testcase, in particular where the unsigned addition is
performed in a wider mode just to catch overflow with a > narrower_utype_max
check.

2020-11-22  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/95853
* tree-ssa-math-opts.c (uaddsub_overflow_check_p): Add maxval
argument, if non-NULL, instead look for r > maxval or r <= maxval
comparisons.
(match_uaddsub_overflow): Pattern recognize even other forms of
__builtin_add_overflow, in particular when addition is performed
in a wider type and result compared to maximum of the narrower
type.

* gcc.dg/pr95853.c: New test.
gcc/testsuite/gcc.dg/pr95853.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c