This testcase: int test (int a) { volatile int z;
z = a + 1; return z; } compiles into: test: subl $16, %esp #, movl 20(%esp), %eax # a, z.0 addl $1, %eax #, z.0 movl %eax, 12(%esp) # z.0, z (1) movl 12(%esp), %eax # z, D.1178 addl $16, %esp #, ret IMO, there is no need for (1), since we already have correct value in %eax. However, even when value lives in another register, we should load it into the return register from the reg, not from mem location. -- Summary: Unnecessary load from volatile var Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ubizjak at gmail dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34282