Community
cancel
Showing results for 
Search instead for 
Did you mean: 
rbarreira
Beginner
107 Views

Bug report - compiler isn't aware that popcnt affects ZF

Hi,

I'm using Intel C++ Compiler version 11.1 under 64-bit Nehalem architecture, with -xSSE4.2 -O3 as optimization options.

I have some code which looks like:

[cpp]int var1 = __builtin_popcountll (x);
int var2 = (y != 0ULL);[/cpp]

The compiler uses testq/cmovne for the second statement, and popcntq for the first. But due to instruction reordering, testq is placed before the popcntq instruction (cmovne after popcntq). According to the Intel instruction set reference, popcnt instructions affect ZF (and other flags too), so this results in wrong behavior (var2 is assigned an incorrect value).

If you need sample source code I will try to provide a small example based on my source code which demonstrates the bug.

Thanks,
Ricardo Barreira

PS: If -xSSE3 or -xSSE4.1 is used the bug does not happen, since the popcntq instruction is not used in that case.
0 Kudos
5 Replies
rbarreira
Beginner
107 Views

OK I managed to get a small program which demonstrates the bug:

> icc -V
Intel C Intel 64 Compiler Professional for applications running on Intel 64, Version 11.1 Build 20100414 Package ID: l_cproc_p_11.1.072

> cat test_bug.c

[cpp]#include 

int main (void)
{
int var1, var2;
unsigned long long x, y;

scanf ("%llu %llu", &x, &y);
var1 = __builtin_popcountll (x);
var2 = (y != 0);
var1 += __builtin_popcountll (var1);

printf ("%d %dn", var1, var2);
return 0;
}[/cpp]


> icc -xSSE4.2 -O3 test_bug.c -o test_bug

> ./test_bug
1 0
2 1

> icc -xSSE4.1 -O3 test_bug.c -o test_bug

> ./test_bug
1 0
2 0


Fragment of incorrect code:

[cpp]   0x000000000040098b <+75>:    mov    $0x1,%r8d
   0x0000000000400991 <+81>:    xor    %edx,%edx
   0x0000000000400993 <+83>:    test   %rcx,%rcx
   0x0000000000400996 <+86>:    popcnt %rsi,%r9
   0x000000000040099b <+91>:    cmovne %r8d,%edx[/cpp]

JenniferJ
Moderator
107 Views

Thank you so much for the small testcase!

I'll send it to compiler team, if there is any progress or news, I'll let you know.

Regards,
Jennifer
Mark_S_Intel1
Employee
107 Views

Thanks for the test case. I reproduced the problem and filed a report on this issue. We will let you know when the problem is resolved.

--mark
rbarreira
Beginner
107 Views

Thanks for submitting the bug.

I saw there's a new compiler update, but I couldn't find this issue in there. Is it fixed or will it only be in a future update?
Mark_S_Intel1
Employee
107 Views

Yes. This problem has been resolved inicc 11.1 build 20100806.

--mark

$ icc -xSSE4.2 -O2 test_bug.c -o test_bug -g
[msabahi@dpd26 74776]$ icc -V -xSSE4.2 -O2 test_bug.c -o test_bug -g
Intel C Intel 64 Compiler Professional for applications running on Intel 64, Version 11.1 Build 20100806 Package ID: l_cproc_p_11.1.073
Copyright (C) 1985-2010 Intel Corporation. All rights reserved.

Edison Design Group C/C++ Front End, version 3.10.1 (Aug 6 2010 19:14:21)
Copyright 1988-2007 Edison Design Group, Inc.

GNU ld version 2.18.50.0.6-7.fc9 20080403
[msabahi@dpd26 74776]$ ./test_bug
1 0
2 0

Reply