tree-ssa-math-opts: Pattern recognize yet another .ADD_OVERFLOW pattern [PR113982]
commitb621482296f6dec0abb22ed39cc4ce6811535d47
authorJakub Jelinek <jakub@redhat.com>
Mon, 13 May 2024 09:15:27 +0000 (13 11:15 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 13 May 2024 09:17:41 +0000 (13 11:17 +0200)
tree40ed7f8c89d3fcae71c25757f86faa44009c9eed
parentf3f02a750c7b34b751fa809ab03d29b2ccf0785d
tree-ssa-math-opts: Pattern recognize yet another .ADD_OVERFLOW pattern [PR113982]

We pattern recognize already many different patterns, and closest to the
requested one also
   yc = (type) y;
   zc = (type) z;
   x = yc + zc;
   w = (typeof_y) x;
   if (x > max)
where y/z has the same unsigned type and type is a wider unsigned type
and max is maximum value of the narrower unsigned type.
But apparently people are creative in writing this in diffent ways,
this requests
   yc = (type) y;
   zc = (type) z;
   x = yc + zc;
   w = (typeof_y) x;
   if (x >> narrower_type_bits)

The following patch implements that.

2024-05-13  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/113982
* tree-ssa-math-opts.cc (arith_overflow_check_p): Also return 1
for RSHIFT_EXPR by precision of maxval if shift result is only
used in a cast or comparison against zero.
(match_arith_overflow): Handle the RSHIFT_EXPR use case.

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