gcc (GCC) 4.4.0 20090109 (experimental) [trunk revision 143212] On x86_64-unknown-linux-gnu (FC9)
Configured as: ../trunk/configure --prefix=/home/ddaney/gccsvn/native-install --disable-multilib --enable-languages=c Consider the following program: ---foo.c--------8<---------------- void bar(int v) { unsigned a; a = (v == 1) ? 1 : 2; if (__builtin_constant_p(a)) { asm volatile ("you lose. %0" : : "ir" (a)); } else { asm volatile ("you win. %0" : : "ir" (a)); } } --------------8<---------------- $ gcc -O2 -S foo.c $ cat foo.s .file "foo.c" .text .p2align 4,,15 .globl bar .type bar, @function bar: .LFB0: .cfi_startproc xorl %eax, %eax cmpl $1, %edi setne %al addl $1, %eax #APP # 9 "foo.c" 1 you lose. %eax # 0 "" 2 #NO_APP ret .cfi_endproc .LFE0: .size bar, .-bar .ident "GCC: (GNU) 4.4.0 20090109 (experimental) [trunk revision 143212]" .section .note.GNU-stack,"",@progbits It emits the asm from the __builtin_constant_p branch of the if statement. Initial analysis points to VRP as being the problem. For the system gcc (gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)) it work correctly. -- Summary: __builtin_constant_p appears to eveluate to true for non-constant arguments. Product: gcc Version: 4.4.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: daney at gcc dot gnu dot org GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789