[Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1

2022-06-16 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984

Jakub Jelinek  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #4 from Jakub Jelinek  ---
Fixed, thanks for the report.

[Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1

2022-06-16 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984

--- Comment #3 from CVS Commits  ---
The master branch has been updated by Jakub Jelinek :

https://gcc.gnu.org/g:74e6a40335765077e235269f19d2d9905d0d9e44

commit r13-1133-g74e6a40335765077e235269f19d2d9905d0d9e44
Author: Jakub Jelinek 
Date:   Thu Jun 16 14:36:04 2022 +0200

match.pd: Fix up __builtin_mul_overflow_p signed type optimization
[PR105984]

Earlier in the simplification pattern, we require that @0 has compatible
type to the type of IMAGPART_EXPR, but for @1 which is a non-zero constant
all we require is that it the constant fits into that type.
Later the code checks if the constant is negative, because when min / max
values are divided by negative divisor, lo will be higher than hi.
In the following testcase, @1 has unsigned char type, while @0 has
int type, so @1 which is 254 is wi::neg_p and we were swapping lo and hi,
even when @1 cast to int isn't negative.

We could use tree_int_cst_sgn (@1) < 0 as the check instead and it would
work both for narrower types of @1 and even same or wider ones, but
I've noticed we probably don't want to call fold_convert (TREE_TYPE (@0),
@1)
twice and when we save that result in a temporary, we can just use
wi::neg_p
on that temporary.

2022-06-16  Jakub Jelinek  

PR tree-optimization/105984
* match.pd (__builtin_mul_overflow_p (x, cst, (stype) 0) ->
x > stype_max / cst || x < stype_min / cst): fold_convert @1
to TREE_TYPE (@0) just once and test for negative divisor
also on that folded constant instead of on @1.

* gcc.c-torture/execute/pr105984.c: New test.

[Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1

2022-06-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984

--- Comment #2 from Jakub Jelinek  ---
Created attachment 53143
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53143=edit
gcc13-pr105984.patch

Untested fix.

[Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1

2022-06-15 Thread jakub at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984

Jakub Jelinek  changed:

   What|Removed |Added

   Last reconfirmed||2022-06-15
 Status|UNCONFIRMED |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org
   Keywords|needs-bisection |
   Priority|P3  |P1
 Ever confirmed|0   |1

--- Comment #1 from Jakub Jelinek  ---
Started with my r13-979-g1982fe2692b6c3b7f969ffc4edac59f9d4359e91

[Bug middle-end/105984] [13 Regression] wrong code with __builtin_mul_overflow_p() at -O1

2022-06-15 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105984

Richard Biener  changed:

   What|Removed |Added

   Keywords||needs-bisection
   Target Milestone|--- |13.0