http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50131
Bug #: 50131 Summary: Optimize x = -1 with "or" for -O Classification: Unclassified Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target AssignedTo: unassig...@gcc.gnu.org ReportedBy: hjl.to...@gmail.com CC: ubiz...@gmail.com [hjl@gnu-6 rtm-1]$ cat x.c int foo1 () { return -1; } short foo2 () { return -1; } long long foo3 () { return -1; } [hjl@gnu-6 rtm-1]$ gcc -S -Os x.c [hjl@gnu-6 rtm-1]$ cat x.s .file "x.c" .text .globl foo1 .type foo1, @function foo1: .LFB0: .cfi_startproc orl $-1, %eax ret .cfi_endproc .LFE0: .size foo1, .-foo1 .globl foo2 .type foo2, @function foo2: .LFB1: .cfi_startproc orl $-1, %eax ret .cfi_endproc .LFE1: .size foo2, .-foo2 .globl foo3 .type foo3, @function foo3: .LFB2: .cfi_startproc orq $-1, %rax ret .cfi_endproc .LFE2: .size foo3, .-foo3 .ident "GCC: (GNU) 4.6.0 20110603 (Red Hat 4.6.0-10)" .section .note.GNU-stack,"",@progbits [hjl@gnu-6 rtm-1]$ gcc -S -O2 x.c [hjl@gnu-6 rtm-1]$ cat x.s .file "x.c" .text .p2align 4,,15 .globl foo1 .type foo1, @function foo1: .LFB0: .cfi_startproc movl $-1, %eax ret .cfi_endproc .LFE0: .size foo1, .-foo1 .p2align 4,,15 .globl foo2 .type foo2, @function foo2: .LFB1: .cfi_startproc movl $-1, %eax ret .cfi_endproc .LFE1: .size foo2, .-foo2 .p2align 4,,15 .globl foo3 .type foo3, @function foo3: .LFB2: .cfi_startproc movq $-1, %rax ret .cfi_endproc .LFE2: .size foo3, .-foo3 .ident "GCC: (GNU) 4.6.0 20110603 (Red Hat 4.6.0-10)" .section .note.GNU-stack,"",@progbits [hjl@gnu-6 rtm-1]$ I was expecting "or" for -O.