[Bug tree-optimization/101610] CST - (x ^ (CST-1)) can be optimized to x + 1 if x < CST and CST is a power of 2

2021-08-03 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101610

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #4 from Andrew Pinski  ---
This is basically PR 91213.

*** This bug has been marked as a duplicate of bug 91213 ***

[Bug tree-optimization/101610] CST - (x ^ (CST-1)) can be optimized to x + 1 if x < CST and CST is a power of 2

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

--- Comment #3 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #2)
> So looking at this one (and one which I just assigned myself):
> unsigned long f(unsigned long x)
> {
> if (x >= 64)__builtin_unreachable();
> x = x ^ 63;
> unsigned long y = x; ;; Range is still [0,63]
> unsigned long z = 64 - y; ;; is similar to (63 - y) +1 -> (y ^ 63) + 1 -> x
> + 1
> return z;
> }
> 
> So mine:
> 
> Something like:
> (simplify
>  (minus INTEGER_CST@0 SSA_NAME@1)
>  (if (exact_power2(@0) && get_nonzero_bits(@1) == (@0 - 1)
>   (add (bit_xor! @1 @0) {build_one_cst (type); }))

But I don't think this should be done at the gimple level unless we have a
place were we decide it should be considered "lowered gimple".
I will be doing a simplify-rtx.c patch for this case which should get some code
generation improvement but not with the original case as we need to export the
non-zero bits down from gimple to RTL still (though I hear someone is working
on keeping around the non-zero bits around through out the whole RTL phase).

[Bug tree-optimization/101610] CST - (x ^ (CST-1)) can be optimized to x + 1 if x < CST and CST is a power of 2

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

Andrew Pinski  changed:

   What|Removed |Added

   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=96921
 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2021-07-28
 Ever confirmed|0   |1
   Assignee|unassigned at gcc dot gnu.org  |pinskia at gcc dot 
gnu.org

--- Comment #2 from Andrew Pinski  ---
So looking at this one (and one which I just assigned myself):
unsigned long f(unsigned long x)
{
if (x >= 64)__builtin_unreachable();
x = x ^ 63;
unsigned long y = x; ;; Range is still [0,63]
unsigned long z = 64 - y; ;; is similar to (63 - y) +1 -> (y ^ 63) + 1 -> x + 1
return z;
}

So mine:

Something like:
(simplify
 (minus INTEGER_CST@0 SSA_NAME@1)
 (if (exact_power2(@0) && get_nonzero_bits(@1) == (@0 - 1)
  (add (bit_xor! @1 @0) {build_one_cst (type); }))

[Bug tree-optimization/101610] CST - (x ^ (CST-1)) can be optimized to x + 1 if x < CST and CST is a power of 2

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

--- Comment #1 from Andrew Pinski  ---
I noticed this while looking into PR 78103.