This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug inline-asm/17272] New: Extra store emitted when concatenating inline assembly sections.


When two inline functions with assembly sections are concatenated, a
superfluous store is emitted between the two calls. Consider the attached
code, where inline functions padd and psub are called in succession from
main(). The optimizer correctly recognizes that the first argument is
the same for both calls and does not touch %dl once it is set. Then the
there is that store between calls even though the compiler should know
that both v1 and v2 are local and not volatile, and are not expected to
be kept up to date after every instruction. It should also know that the
value is overwritten again after only one instruction. Although the extra
store is not in itself harmful, removing it would improve performance.

============================================================
inline void padd (const char* p, char* r)
{
    asm ("addb %1, %0" : "=&r"(*r) : "r"(*p), "0"(*r));
}

inline void psub (const char* p, char* r)
{
    asm ("subb %1, %0" : "=&r"(*r) : "r"(*p), "0"(*r));
}

int main (void)
{
    char v1[8] = "v1";
    char v2[8] = "v2";
    padd (v1, v2);
    psub (v1, v2);
    return (v2[0]);
}
============================================================
-O3 -march=athlon-mp
============================================================
main:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%ebx
	subl	$4, %esp
	movl	.LC1, %eax
	movzbl	.LC0, %edx
	andl	$-16, %esp
	subl	$16, %esp
	movl	%eax, %ebx
#APP
	addb %dl, %bl
#NO_APP
	movb	%bl, %al	<<< Unneeded
#APP
	subb %dl, %bl
#NO_APP
	movb	%bl, %al        <<< Overwritten here
	movl	-4(%ebp), %ebx
	leave
	movsbl	%al,%eax
	ret
============================================================

-- 
           Summary: Extra store emitted when concatenating inline assembly
                    sections.
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: inline-asm
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: msharov at talentg dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: athlon-gnu-linux
  GCC host triplet: athlon-gnu-linux
GCC target triplet: athlon-gnu-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17272


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]