From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26306 invoked by alias); 18 Nov 2012 00:15:35 -0000 Received: (qmail 25396 invoked by uid 48); 18 Nov 2012 00:15:07 -0000 From: "stevenbaker94 at rocketmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/55372] New: MIPS: Loading integer constants to floating-pointer registers generates suboptimal code Date: Sun, 18 Nov 2012 00:15:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: stevenbaker94 at rocketmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg01619.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55372 Bug #: 55372 Summary: MIPS: Loading integer constants to floating-pointer registers generates suboptimal code Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: target AssignedTo: unassigned@gcc.gnu.org ReportedBy: stevenbaker94@rocketmail.com When loading an integer constant (e.g. 100) into a floating-point variable, the compiler unconditionally creates a .rodata entry. However, integer constants that are to be used in floating-point registers always have the lower 16 bits set to 0, so it is better to use the combination lui+mtc1 rather than lui+lwc1 and a .data entry. (In other words, we save both a word of memory in .data and one memory fetch for this word.) As a workaround, I provide a function f() that "converts" a const float into float using the right instruction sequence (beware that it silently discards any fractional bits, however): extern void foo(float x); static inline float f(const float f) { union { float f; unsigned int i; } x; x.f = f; unsigned int r; float f_out; asm ("lui %0, %1" : "=d" (r) : "I" (x.i >> 16)); asm ("mtc1 %1, %0" : "=f" (f_out) : "d" (r)); return f_out; } void bar() { #if 1 /* Workaround */ foo(f(100.0f)); #else /* Native GCC */ foo(100.0f); #endif } The difference: ORIGINAL: Contents of section .rodata.cst4: 0000 42c80000 B... 00000000 : 0: 3c020000 lui v0,0x0 4: 08000000 j 0 8: c44c0000 lwc1 $f12,0(v0) WORKAROUND/PROPOSED IMPROVEMENT: 00000000 : 0: 3c0242c8 lui v0,0x42c8 4: 08000000 j 0 8: 44826000 mtc1 v0,$f12