This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/69984] [4.9/5/6] Signed comparison instruction emitted for unsigned variable comparison
- From: "edmar at freescale dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 29 Feb 2016 16:10:08 +0000
- Subject: [Bug tree-optimization/69984] [4.9/5/6] Signed comparison instruction emitted for unsigned variable comparison
- Auto-submitted: auto-generated
- References: <bug-69984-4 at http dot gcc dot gnu dot org/bugzilla/>
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