Bug 54988 - fpmath=sse target pragma causes inlining failure because of target specific option mismatch
fpmath=sse target pragma causes inlining failure because of target specific o...
Status: ASSIGNED
Product: gcc
Classification: Unclassified
Component: c++
4.7.2
: P3 normal
: ---
Assigned To: Jakub Jelinek
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-10-19 15:36 UTC by Olivier Blin
Modified: 2013-03-27 09:12 UTC (History)
8 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-10-22 00:00:00


Attachments
gcc48-pr54988.patch (1.25 KB, patch)
2012-10-22 10:54 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Blin 2012-10-19 15:36:13 UTC
#pragma GCC target "fpmath=sse"

static inline __attribute__((always_inline)) int a(int x) { return x; }

int b(int src)
{
    return a(src);
}

$ gcc -O1 ./qdrawhelper_test.cpp -c
./qdrawhelper_test.cpp: In function 'int b(int)':
./qdrawhelper_test.cpp:3:50: error: inlining failed in call to always_inline 'int a(int)': target specific option mismatch
./qdrawhelper_test.cpp:7:17: error: called from here

I have the patch from bug 33763 applied in this gcc 4.7.2 build, if that matters.

This bug initially happened when building Qt5 with gcc -m32 on a x86_64 host (gcc being configured without any --with-arch_32 option), in qt5/qtbase/src/gui/painting/qdrawhelper.cpp:
In file included from ../../include/QtGui/5.0.0/QtGui/private/qdrawhelper_p.h:1:0,
                 from /home/sah0146/dev/workspaces/pc32/stb/opensource/LGPL/qt/vendor/qt.gitorious.org/MAIN/qt5/qtbase/src/gui/painting/qdrawhelper.cpp:54:
../../include/QtGui/5.0.0/QtGui/private/../../../../../../../qt5/qtbase/src/gui/painting/qdrawhelper_p.h: In function 'int multiply_op(int, int, int, int)':
../../include/QtGui/5.0.0/QtGui/private/../../../../../../../qt5/qtbase/src/gui/painting/qdrawhelper_p.h:797:30: error: inlining failed in call to always_inline 'int qt_div_255(int)': target specific option mismatch
/home/sah0146/dev/workspaces/pc32/stb/opensource/LGPL/qt/vendor/qt.gitorious.org/MAIN/qt5/qtbase/src/gui/painting/qdrawhelper.cpp:2498:70: error: called from here

Bug 41201 might be related, even if it mentions C++ only.
Comment 1 Richard Biener 2012-10-22 09:15:19 UTC
It's interesting to note that this only fails when using the C++ frontend,
and only when optimizing(!).  b does not have target specific optimization
assigned for C++ while a has.

Thus this is a C++ frontend issue.
Comment 2 Jakub Jelinek 2012-10-22 10:54:25 UTC
Created attachment 28504 [details]
gcc48-pr54988.patch

Untested fix.  Apparently the C++ FE assumes that if attributes is NULL, decl_attributes does nothing, which isn't true for FUNCTION_DECLs.
Comment 3 Thiago Macieira 2012-10-22 14:43:11 UTC
This might be as I pointed out in http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54231:

(Node "Function attributes"):

     On the 386/x86_64 and PowerPC backends, the inliner will not
     inline a function that has different target options than the
     caller, unless the callee has a subset of the target options of
     the caller.  For example a function declared with `target("sse3")'
     can inline a function with `target("sse2")', since `-msse3'
     implies `-msse2'.

My guess was that we were forcing the inlining (via always_inline) of a function that has different target options.

But I guess that doesn't explain why it happens only in C++ and only in optimising mode. Does always_inline inline on -O0 too?
Comment 4 Olivier Blin 2012-10-23 12:21:52 UTC
Thanks Jakub, I can confirm that your patch fixes both the small testcase and the Qt5 qdrawhelper issues (applied on top of gcc 4.7.2)
Comment 5 Jakub Jelinek 2012-10-23 16:56:01 UTC
Author: jakub
Date: Tue Oct 23 16:55:56 2012
New Revision: 192722

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192722
Log:
	PR c++/54988
	* decl2.c (cplus_decl_attributes): Don't return early
	if attributes is NULL.

	* c-c++-common/pr54988.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/pr54988.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2012-10-23 17:56:04 UTC
Author: jakub
Date: Tue Oct 23 17:55:56 2012
New Revision: 192734

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192734
Log:
	PR c++/54988
	* decl2.c (cplus_decl_attributes): Don't return early
	if attributes is NULL.

	* c-c++-common/pr54988.c: New test.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/cp/ChangeLog
Comment 7 Jakub Jelinek 2012-10-24 09:52:20 UTC
Fixed on the trunk so far.
Comment 8 Oleg Endo 2012-10-30 09:07:17 UTC
Author: olegendo
Date: Tue Oct 30 09:07:08 2012
New Revision: 192982

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192982
Log:
	PR target/54988
	* config/sh/sh.md (tstqi_t_zero): Rename to *tstqi_t_zero.
	(*tst<mode>_t_zero): New insns.
	* config/sh/iterators.md (lowpart_be, lowpart_le): New mode attributes.

	PR target/54988
	* gcc.target/sh/pr53988.c: New.


Added:
    trunk/gcc/testsuite/gcc.target/sh/pr53988.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/sh/iterators.md
    trunk/gcc/config/sh/sh.md
    trunk/gcc/testsuite/ChangeLog
Comment 9 Oleg Endo 2012-10-31 22:09:10 UTC
(In reply to comment #8)
> Author: olegendo
> Date: Tue Oct 30 09:07:08 2012
> New Revision: 192982
> 
> URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192982
> Log:
>     PR target/54988
>     * config/sh/sh.md (tstqi_t_zero): Rename to *tstqi_t_zero.
>     (*tst<mode>_t_zero): New insns.
>     * config/sh/iterators.md (lowpart_be, lowpart_le): New mode attributes.
> 
>     PR target/54988
>     * gcc.target/sh/pr53988.c: New.
> 
> 
> Added:
>     trunk/gcc/testsuite/gcc.target/sh/pr53988.c
> Modified:
>     trunk/gcc/ChangeLog
>     trunk/gcc/config/sh/iterators.md
>     trunk/gcc/config/sh/sh.md
>     trunk/gcc/testsuite/ChangeLog

Sorry for the typo in the PR number of the ChangeLog.  ChangeLog fixed, commit message posted to PR 53988.
Comment 10 Jakub Jelinek 2012-11-05 15:07:22 UTC
Author: jakub
Date: Mon Nov  5 15:07:14 2012
New Revision: 193165

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=193165
Log:
	Backported from mainline
	2012-10-23  Jakub Jelinek  <jakub@redhat.com>

	PR c++/54988
	* decl2.c (cplus_decl_attributes): Don't return early
	if attributes is NULL.

	* c-c++-common/pr54988.c: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/c-c++-common/pr54988.c
Modified:
    branches/gcc-4_7-branch/gcc/cp/ChangeLog
    branches/gcc-4_7-branch/gcc/cp/decl2.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
Comment 11 Jonathan Liu 2013-01-15 08:40:55 UTC
#pragma GCC optimize "O2"
#include <mshtmlc.h> // big header that's part of MinGW-builds

C:\gcc_oom>g++ -c -o release\test.o test.cpp

cc1plus.exe: out of memory allocating 177249 bytes

The patch is causing out of memory error on Windows with MinGW-builds GCC 4.7.2 32-bit (http://download.sourceforge.net/project/mingwbuilds/host-windows/releases/4.7.2/32-bit/threads-posix/sjlj/x32-4.7.2-release-posix-sjlj-rev7.7z).
Comment 12 Alexey Pavlov 2013-01-15 08:53:25 UTC
Confirm the issue with allocation memory for rev.195125 of gcc-4_7 from branch too (http://sourceforge.net/projects/mingwbuilds/files/host-windows/testing/4.7.3/32-bit/threads-posix/sjlj/x32-4.7.3-prerelease-20130114-rev195125-posix-sjlj.7z)
Comment 13 Kai Koehne 2013-03-27 09:12:42 UTC
The OOM problem is still there with gcc 4.8.0 on MinGW: Any #pragma optimize "X" will result in OOM for big files.