]> git.ipfire.org Git - thirdparty/gcc.git/commit
match.pd: Fix up __imag__ .MUL_OVERFLOW simplification [PR123864]
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 Jan 2026 10:42:41 +0000 (11:42 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Jan 2026 10:42:41 +0000 (11:42 +0100)
commit238d2fc116cdef31c3d643e71ade0875b5cba110
treee2b8c92fc2c68d35575af1684d567ab2708ee159
parentcffe5fd7c98babd85acf86f3e7f8d02b04416ec2
match.pd: Fix up __imag__ .MUL_OVERFLOW simplification [PR123864]

The integer_minus_onep case is really meant for multiplication by
-1, not by (unsigned char)0xff or (unsigned short)0xffff or 0xffffffffU etc.
We've already tested that the first operand is signed (otherwise the
earlier case is used) and also that int_fits_type_p (@1, TREE_TYPE (@0)),
but if @0 is signed and @1 is unsigned all ones with smaller precision
than that, it fits into @0's type, integer_minus_onep will be true
and it still should be handled through the ranges, not as @0 == min.

2026-01-30  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/123864
* match.pd (__builtin_mul_overflow_p (x, cst, (stype) 0) ->
x > stype_max / cst || x < stype_min / cst): Only check
integer_minus_onep for signed types.

* gcc.c-torture/execute/pr123864.c: New test.
* gcc.dg/torture/pr123864.c: New test.
gcc/match.pd
gcc/testsuite/gcc.c-torture/execute/pr123864.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr123864.c [new file with mode: 0644]