widening_mul: Pattern recognize unsigned multiplication with overflow check [PR95852]
authorJakub Jelinek <jakub@redhat.com>
Mon, 11 Jan 2021 09:32:07 +0000 (10:32 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 11 Jan 2021 09:32:19 +0000 (10:32 +0100)
commita2106317cd6673e110b347c70f21e25fbb23379e
treea7f2fa222c89b85f8e86db28c9ab3fc906845719
parent64dc013853b5a414bfe70727010942e3f872c402
widening_mul: Pattern recognize unsigned multiplication with overflow check [PR95852]

The following patch pattern recognizes some forms of multiplication followed
by overflow check through division by one of the operands compared to the
other one, with optional removal of guarding non-zero check for that operand
if possible.  The patterns are replaced with effectively
__builtin_mul_overflow or __builtin_mul_overflow_p.  The testcases cover 64
different forms of that.

2021-01-11  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/95852
* tree-ssa-math-opts.c (maybe_optimize_guarding_check): New function.
(uaddsub_overflow_check_p): Renamed to ...
(arith_overflow_check_p): ... this.  Handle also multiplication
with overflow check.
(match_uaddsub_overflow): Renamed to ...
(match_arith_overflow): ... this.  Add cfg_changed argument.  Handle
also multiplication with overflow check.  Adjust function comment.
(math_opts_dom_walker::after_dom_children): Adjust callers.  Call
match_arith_overflow also for MULT_EXPR.

* gcc.target/i386/pr95852-1.c: New test.
* gcc.target/i386/pr95852-2.c: New test.
gcc/testsuite/gcc.target/i386/pr95852-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr95852-2.c [new file with mode: 0644]
gcc/tree-ssa-math-opts.c