The following test program generates extra use of a temporary register for the return value. I have narrowed the cause of the poor code generation to the addition of the pos = file->f_pos; line -- removing it causes the extra temporary register to disappear (and saves several unnecessary mov instructions).
/* compile with gcc -O2 -fomit-frame-pointer -fno-asynchronous-unwind-tables -S -o fs/test-sys-read.s fs/test-sys-read.c && cat fs/test-sys-read.s */ struct file { long f_pos; }; struct file *fget_light(unsigned int fd); long vfs_read(struct file *, char *, unsigned long, long *); static inline int IS_ERR(const void *ptr) { return (unsigned long)ptr > (unsigned long)-1000L; } long sys_read(unsigned int fd, char *buf, unsigned long count) { struct file *file; long ret, pos; file = fget_light(fd); if (IS_ERR(file)) { pos = file->f_pos; // comment this line to get better code ret = vfs_read(file, buf, count, &pos); } else ret = (long)file; return ret; } -- Summary: code generation -- extra instructions generated Product: gcc Version: 4.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: bcrl at kvack dot org GCC build triplet: x86_64-unknown-linux GCC host triplet: x86_64-unknown-linux GCC target triplet: x86_64-unknown-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25225