Messages in this thread | | | Date | Tue, 19 Aug 2003 02:15:07 +0200 | From | "J.A. Magallon" <> | Subject | gcc -O3 and register usage |
| |
Hi all...
I was playing looking at the code gcc gives for some simple operations, and got this...
Simple C program (do you recognise it ;) ?):
struct list_head { struct list_head *next, *prev; };
static inline int list_empty(struct list_head *head) { return head->next == head; }
int use(struct list_head *l) { return list_empty(l); }
I use gcc 3.3.1. Compile at -O2:
use: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax popl %ebp cmpl %eax, (%eax) sete %al movzbl %al, %eax ret
Compile at -O3:
use: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx popl %ebp cmpl %edx, (%edx) sete %al andl $255, %eax ret
Compile at -O3 and (at least) -march=pentiumpro:
use: pushl %ebp movl %esp, %ebp movl 8(%ebp), %edx popl %ebp cmpl %edx, (%edx) sete %dl movzbl %dl, %eax ret
Go back to -O2, but keep -march=pentiumpro:
use: pushl %ebp movl %esp, %ebp movl 8(%ebp), %eax popl %ebp cmpl %eax, (%eax) sete %al movzbl %al, %eax ret
Does this mean that since PentiumPro gcc has one other register (%dl) available, and it uses it only at -O3 ? This can be a _big_ advantage to reduce register spilling (stack traffic...)
The above effect is due to the -frename-registers activated in -O3. This option is used in arch/ia64/Makefile, but it is supposed to benefit more to arches with few registers (I suppose ia64 has a ton more that ia32...)
Would if be useful ?
TIA
-- J.A. Magallon <jamagallon@able.es> \ Software is like sex: werewolf.able.es \ It's better when it's free Mandrake Linux release 9.2 (Cooker) for i586 Linux 2.4.22-rc2-jam1m (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-1mdk)) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |