https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118456

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
With -Wtautological-compare it even incorrectly warns:
./cc1 -quiet -O2 auu.c -Wtautological-compare; gcc -o auu{,.s}; ./auu
auu.c: In function ‘foo’:
auu.c:6:43: warning: comparison is always 0 [-Wtautological-compare]
    6 |   return ((unsigned char) s.a) >> 3 == 17 && ((signed char) s.b) >> 2
== -27;
      |         
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is for the ((signed char) s.b) >> 2 == -27 comparison, where it correctly
determines that 6 bits are tested, but because there is an arithmetic right
shift involved, nothing understands that it isn't always 0 if r_const is not in
the [0, 63]
range, but when r_const is not in the [-32, 31] range.
While in the first case it was logical right shift and so it would be always 0
if rr_arg was not in [0, 31] range (5 bit unsigned).
On the other side, if we somehow force in say && ((signed char) s.b) >> 2 == 62
and ensure it isn't really optimized by earlier optimization passes to 0
(perhaps GIMPLE FE testcase?), and ifcombine decides to fold it with something
else, we should emit the -Wtautological-compare warning and fold it to 0.

Reply via email to