This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/82001] New: [5/6/7/8 regression] wrong code when two functions differ only in inline asm register constraints
- From: "peter at cordes dot ca" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 28 Aug 2017 05:46:11 +0000
- Subject: [Bug inline-asm/82001] New: [5/6/7/8 regression] wrong code when two functions differ only in inline asm register constraints
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82001
Bug ID: 82001
Summary: [5/6/7/8 regression] wrong code when two functions
differ only in inline asm register constraints
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: inline-asm
Assignee: unassigned at gcc dot gnu.org
Reporter: peter at cordes dot ca
Target Milestone: ---
Target: x86_64-*-*, i?86-*-*
When a single compilation unit contains two functions that are identical other
than specific-register constraints in an asm statement, they are incorrectly
treated as exactly identical and the same code is emitted for both.
This happens at -O2 or higher, not -O1.
I was able to construct this test-case with two functions that are both
plausibly useful. (Although this actually came up while discussing a beginner
SO question about inline asm.
https://stackoverflow.com/questions/45910530/how-to-write-a-short-block-of-inline-gnu-extended-assembly-to-swap-the-values-of#comment78780443_45910796)
int mullo(int a, int b) {
asm("mul %%edx # %%1 was %1" : "+a" (a), "+d" (b));
return a;
}
int mulhi(int a, int b) {
asm("mul %%edx # %%1 was %1" : "+d" (a), "+a" (b));
return a;
}
gcc8.0.0-snapshot 20170827 -O3 (https://godbolt.org/g/CYjnGg) compiles them
both to
movl %edi, %eax # a, a
movl %esi, %edx # b, b
mul %edx # %1 was %edx # b
ret
Any difference in the asm string, or in the clobber registers, makes them not
match. Also, an "m" constraint is seen as different from an "r" or
specific-register constraint, but "imr" can "match" an "r"
In gcc6/7/8, both functions use the correct asm for the 1st function. Swapping
the order changes the asm to the other one.
In gcc5.x, both functions use the correct asm for the 2nd function.
In gcc4.9.4, both functions are compiled correctly.