[Bug middle-end/78115] Missed optimization for "int modulo 2^31"

2023-06-07 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78115

--- Comment #6 from Andrew Pinski  ---
What this needs above and beyond PR 103216 is supporting `x ? a - b : a`.

[Bug middle-end/78115] Missed optimization for "int modulo 2^31"

2023-05-24 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78115

Andrew Pinski  changed:

   What|Removed |Added

 Blocks||90087
 CC||nok.raven at gmail dot com

--- Comment #5 from Andrew Pinski  ---
*** Bug 90087 has been marked as a duplicate of this bug. ***


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90087
[Bug 90087] Suboptimal codegen for x < 0 ? x - INT_MIN : x

[Bug middle-end/78115] Missed optimization for "int modulo 2^31"

2021-11-15 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78115

Andrew Pinski  changed:

   What|Removed |Added

 Depends on||103216
 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |pinskia at gcc dot 
gnu.org

--- Comment #4 from Andrew Pinski  ---
The patch which I posted for PR 103216 will fix this one too:
https://gcc.gnu.org/pipermail/gcc-patches/2021-November/584411.html

in phiopt4:
COND_EXPR in block 2 and PHI in block 4 converted to straightline code.
Merging blocks 2 and 4
fix_loop_structure: fixing up loops for function
int mod31 (int num)
{
  _Bool _5;
  int _6;
  int _7;
  int _8;

   [local count: 1073741824]:
  _5 = num_2(D) < 0;
  _6 = (int) _5;
  _7 = num_2(D) & -2147483648;
  _8 = num_2(D) & 2147483647;
  return _8;

}


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103216
[Bug 103216] missed optimization, phiopt/vrp?

[Bug middle-end/78115] Missed optimization for "int modulo 2^31"

2021-07-20 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78115

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

--- Comment #3 from Andrew Pinski  ---
We get now:
  if (num_2(D) < 0)
goto ; [41.00%]
  else
goto ; [59.00%]

   [local count: 440234144]:
  num_3 = num_2(D) - -2147483648;

   [local count: 1073741824]:
  # num_1 = PHI 

So something like (psedu code):
(simplify
 (cond (lt @0 integer_zerop) (minus @0 INTEGER_CST@1) @0)
 (if (TYPE_SIGN (type) == SIGNED && @1 == type_min(type))
  (bit_and @0 type_max(type

[Bug middle-end/78115] Missed optimization for "int modulo 2^31"

2016-10-27 Thread glisse at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78115

--- Comment #2 from Marc Glisse  ---
For the first part, when we transform (X+C1)+C2 to X+(C1+C2), we check that
C1+C2 doesn't overflow. But if C1+C2 would give INT_MIN, we still have the
possibility to generate X-INT_MIN without going to an unsigned type.

For the second part, I am not sure either. Some guesses:
X - INT_MIN becomes X ^ INT_MIN. Since we know that all the bits set in INT_MIN
(the top one) are also set in X (< 0), this becomes X & INT_MAX. In the branch
X >= 0, X & INT_MAX would fold to X (kind of like a neutral element) so we can
do the operation unconditionally.
A bit far-fetched maybe...

[Bug middle-end/78115] Missed optimization for "int modulo 2^31"

2016-10-27 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78115

Richard Biener  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-10-27
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
GCC is pessimized by its own IL (with undefined overflow).  Optimized we have:

  :
  if (num_3(D) < 0)
goto ;
  else
goto ;

  :
  _1 = num_3(D) + 1;
  num_4 = _1 + 2147483647;

  :
  # num_2 = PHI 
  return num_2;

not sure what exactly clang matches here.