[Bug tree-optimization/113411] ABS*ABS can be simplified to ABS

2024-01-21 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113411

Andrew Pinski  changed:

   What|Removed |Added

 Blocks||56355

--- Comment #2 from Andrew Pinski  ---
PR 56355 is the same but for floating point already ...


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56355
[Bug 56355] abs and multiplication

[Bug tree-optimization/113411] ABS*ABS can be simplified to ABS

2024-01-16 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113411

Richard Biener  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2024-01-16
 Status|UNCONFIRMED |NEW

--- Comment #1 from Richard Biener  ---
I think it's OK for reals with -fno-rounding-math.

It's valid for integers with or without undefined overflow, the corner
case to consider is

  abs(-INT_MAX - 1) * abs (b)

where with undefined overflow the abs() is already invoking undefined
behavior.  The problematical multiplication is (-INT_MAX-1) * -1 but
we cannot arrive at this from a defined input.  For

  abs(a*b)

the problematical input is -INT_MAX - 1 but we can't arrive at that
either (b == 1 with a == -INT_MAX-1 is undefined, b == -1 the same).