https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105776
--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:bd0f2828432918a16e93d9e9021a5927143b8dde commit r14-993-gbd0f2828432918a16e93d9e9021a5927143b8dde Author: Jakub Jelinek <ja...@redhat.com> Date: Fri May 19 12:58:32 2023 +0200 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 <ja...@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.