This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/69984] [4.9/5/6] Signed comparison instruction emitted for unsigned variable comparison


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

--- Comment #4 from Edmar Wienskoski <edmar at freescale dot com> ---
I forgot that default on x86 is 64 bits.
Repeating the test with -m32 still shows the signed comparison.

Here:
#include <stdio.h>

void main ()
{
  unsigned short int A, B;
  unsigned long C,D;
  unsigned long E = 0xFFFEFFEUL;

  scanf("%hu %hu %lu", &A, &B, &D);
  C=A*B;

  printf("A:%08X, B:%08X, C:%08X, D:%08X, E:%08X\n", A, B, C, D, E);

  if (C <= D)
    printf("C<=D\n");
  if (C <= E)                      //this compare has issue
    printf("C<=E\n");

}

Compiling with:
gcc -O3 -m32 -o unsig_comp unsig_comp.c

And excuting as:
 ./unsig_comp
65535 65535 65535
A:0000FFFF, B:0000FFFF, C:FFFE0001, D:0000FFFF, E:0FFFEFFE
C<=E

gives me the wrong answer.

The same problem with -m64 as well, but because the compiler
reduces one of the comparisons to 32 bits:
        cmpq    8(%rsp), %rbp
        jbe     .L6
.L2:
        cmpl    $268431358, %ebx
        jg      .L1

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]