This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug inline-asm/48992] New: inline assembly "i" constraint does not accept constexpr function return value
- From: "hvdieren at elis dot ugent.be" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 13 May 2011 21:09:13 +0000
- Subject: [Bug inline-asm/48992] New: inline assembly "i" constraint does not accept constexpr function return value
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48992
Summary: inline assembly "i" constraint does not accept
constexpr function return value
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: inline-asm
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hvdieren@elis.ugent.be
constexpr functions would be helpful to improve the performance of inline
assembly by passing the constant value as an assembly constant rather than
through a register.
In the following simplified example we want to add a constant to a variable.
constexpr int const_func() { return 12; }
int main(int argc, char * argv[]) {
int ret;
__asm__( "add %2,%0" : "=g"(ret) : "0"(argc), "i"(const_func()) : );
return ret;
}
If we put an "r" constraint instead of an "i", then gcc will load the constant
in a register first:
movl %edi,%eax
movl $0x0000000c,%edx
addl %edx,%eax
ret
but what we want is obviously
movl %edi,%eax
addl $0x0000000c,%eax
ret
With -O4, constexpr can generally be passed to an "i" constraint, but not at
-O0 which we use for debugging:
$ gcc-mp-4.6 -std=c++0x -O0 -o asm_constexpr asm_constexpr.cc
asm_constexpr.cc: In function 'int main(int, char**)':
asm_constexpr.cc:5:72: warning: asm operand 2 probably doesn't match
constraints [enabled by default]
asm_constexpr.cc:5:72: error: impossible constraint in 'asm'
The reason is that the constexpr function is evaluated at runtime at -O0.
In short, the feature request is that inline assembly "i" constraints (and
potentially other types of constant constraints) should accept return values
from constexpr functions, also at -O0.