]> git.ipfire.org Git - thirdparty/gcc.git/commit
tree-ssa-math-opts: Pattern recognize some further hand written forms of signed __bui...
authorJakub Jelinek <jakub@redhat.com>
Fri, 19 May 2023 10:58:32 +0000 (12:58 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 19 May 2023 10:58:32 +0000 (12:58 +0200)
commitbd0f2828432918a16e93d9e9021a5927143b8dde
treedd3ffe4b3e718ccb5e852b31bbd2fc0d42dc5ee9
parent62d08a67c83b4a089866c6d19e82d70ee5b8aed1
tree-ssa-math-opts: Pattern recognize some further hand written forms of signed __builtin_mul_overflow{,_p} [PR105776]

In the pattern recognition of signed __builtin_mul_overflow{,_p} we
check for result of unsigned division (which follows unsigned
multiplication) being equality compared against one of the multiplication's
argument (the one not used in the division) and check for the comparison
to be done against same precision cast of the argument (because
division's result is unsigned and the argument is signed).
But as shown in this PR, one can write it equally as comparison done in
the signed type, i.e. compare division's result cast to corresponding
signed type against the argument.

The following patch handles even those cases.

2023-05-19  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/105776
* tree-ssa-math-opts.cc (arith_overflow_check_p): If cast_stmt is
non-NULL, allow division statement to have a cast as single imm use
rather than comparison/condition.
(match_arith_overflow): In that case remove the cast stmt in addition
to the division statement.

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