[Bug tree-optimization/102738] Failure to optimize (signed) right shift if the range is already known to be [-1, 0]

2021-10-13 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102738

Andrew Pinski  changed:

   What|Removed |Added

Summary|Failure to optimize right   |Failure to optimize
   |shift of 32-bit int after   |(signed) right shift if the
   |it's already been shifted   |range is already known to
   |by 31   |be [-1, 0]
   Severity|normal  |enhancement

[Bug tree-optimization/102738] Failure to optimize (signed) right shift if the range is already known to be [-1, 0]

2021-10-13 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102738

--- Comment #2 from Andrew Pinski  ---
So this is interesting, I think clang/LLVM does this optimization late in their
pipeline take:
int a1(int f, int g)
{
if (f == 0 || f == 1)
return (f-1) >> g;
return 0;
}
They don't remove the shift at all.  But if you change return 0 to
__builtin_unreachable(), they remove the shift.

Anyways we should be able to do this optimization even in the above case.

And even here where clang/LLVM misses too:
int a1(int f, int g)
{
if (f == 6 || f == 7)
return (f-7) >> g;
__builtin_unreachable();
}

[Bug tree-optimization/102738] Failure to optimize (signed) right shift if the range is already known to be [-1, 0]

2021-10-14 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102738

--- Comment #3 from CVS Commits  ---
The master branch has been updated by Andrew Macleod :

https://gcc.gnu.org/g:f0b7d4cc49ddb1c2c7474cc3f61e260aa93a96c0

commit r12-4413-gf0b7d4cc49ddb1c2c7474cc3f61e260aa93a96c0
Author: Andrew MacLeod 
Date:   Thu Oct 14 10:43:58 2021 -0400

Simplification for right shift.

When the first operand of a signed right shift is zero or negative one, the
RHS doesn't matter and the shift can be converted to a copy.

PR tree-optimization/102738
gcc/
* vr-values.c (simplify_using_ranges::simplify): Handle
RSHIFT_EXPR.

gcc/testsuite
* gcc.dg/pr102738.c: New.

[Bug tree-optimization/102738] Failure to optimize (signed) right shift if the range is already known to be [-1, 0]

2021-10-14 Thread amacleod at redhat dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102738

Andrew Macleod  changed:

   What|Removed |Added

 CC||amacleod at redhat dot com
 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #4 from Andrew Macleod  ---
I added this to the simplifier, so we now get all these cases right in EVRP.  
I incorporated all 6 into one test.