public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas
@ 2021-12-13 20:30 imachug at gmail dot com
2021-12-13 20:33 ` [Bug target/103696] " imachug at gmail dot com
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: imachug at gmail dot com @ 2021-12-13 20:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
Bug ID: 103696
Summary: Lambda functions are not inlined under certain
optimization pragmas
Product: gcc
Version: 11.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: imachug at gmail dot com
Target Milestone: ---
This seems like a very weird bug to me and I'm not even sure how to label it,
so please fix the component if needed.
Testcase (C++):
#pragma GCC optimize("finite-math-only")
#pragma GCC target("sse3")
void fn() {
}
int global_var;
int solve() {
auto nested = []() {
return global_var;
};
return nested();
}
When compiling this code via `g++ test.cpp -c -O2 -std=c++17`, I get the
following assembly:
$ objdump -d test.o
...
0000000000000000 <_ZZ5solvevENKUlvE_clEv.constprop.0>:
0: 8b 05 00 00 00 00 mov 0x0(%rip),%eax # 6
<_ZZ5solvevENKUlvE_clEv.constprop.0+0x6>
6: c3 retq
7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
e: 00 00
...
0000000000000020 <_Z5solvev>:
20: f3 0f 1e fa endbr64
24: e8 d7 ff ff ff callq 0 <_ZZ5solvevENKUlvE_clEv.constprop.0>
29: c3 retq
As you can see, the nested() lambda call was not inlined into solve().
However, if I do any of the following, the lambda is inlined as expected:
- Remove `fn` definition
- Move `fn` definition under `solve`
- Replace reading `global_var` with a constant
- Make `nested` a global function
- Remove either of the two pragmas (or both)
- Add -ffinite-math-only or -msse3 or both to the compilation line (regardless
of whether the pragmas are still there)
I have absolutely no idea why a floating point optimization affects inlining or
how a pragma is different from a compilation line option wrt. this bug.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug target/103696] Lambda functions are not inlined under certain optimization pragmas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
@ 2021-12-13 20:33 ` imachug at gmail dot com
2021-12-14 1:14 ` [Bug c++/103696] pragma optimization is not applying to Lambdas pinskia at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: imachug at gmail dot com @ 2021-12-13 20:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
--- Comment #1 from Ivan Machugovskiy <imachug at gmail dot com> ---
Obligatory info dump. I managed to reproduce this on G++ 9.3.0 and G++ 10.3.0
locally, and on G++ trunk on Godbolt (see https://godbolt.org/z/Y5Kr3KfjW).
This is probably a longstanding bug.
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-9
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
$ g++-10 -v
Using built-in specs.
COLLECT_GCC=g++-10
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
10.3.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-10-S4I5Pr/gcc-10-10.3.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-S4I5Pr/gcc-10-10.3.0/debian/tmp-gcn/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
--with-build-config=bootstrap-lto-lean --enable-link-mutex
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103696] pragma optimization is not applying to Lambdas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
2021-12-13 20:33 ` [Bug target/103696] " imachug at gmail dot com
@ 2021-12-14 1:14 ` pinskia at gcc dot gnu.org
2021-12-14 16:59 ` marxin at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-14 1:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2021-12-14
Summary|Lambda functions are not |pragma optimization is not
|inlined under certain |applying to Lambdas
|optimization pragmas |
Keywords| |wrong-code
Blocks| |54367
Component|target |c++
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
If I manually apply the attributes rather than use the pragma, I get the
correct results.
that is the following works:
int global_var;
[[gnu::optimize("finite-math-only"),gnu::target("sse3")]]
int solve() {
auto nested =
[]
[[gnu::optimize("finite-math-only"),gnu::target("sse")]]
() {
return global_var;
};
return nested();
}
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54367
[Bug 54367] [meta-bug] lambda expressions
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103696] pragma optimization is not applying to Lambdas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
2021-12-13 20:33 ` [Bug target/103696] " imachug at gmail dot com
2021-12-14 1:14 ` [Bug c++/103696] pragma optimization is not applying to Lambdas pinskia at gcc dot gnu.org
@ 2021-12-14 16:59 ` marxin at gcc dot gnu.org
2021-12-16 11:08 ` marxin at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-14 16:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |marxin at gcc dot gnu.org
Status|NEW |ASSIGNED
CC| |marxin at gcc dot gnu.org
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Confirmed, debugging that right now.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103696] pragma optimization is not applying to Lambdas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
` (2 preceding siblings ...)
2021-12-14 16:59 ` marxin at gcc dot gnu.org
@ 2021-12-16 11:08 ` marxin at gcc dot gnu.org
2021-12-16 16:52 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-16 11:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #4 from Martin Liška <marxin at gcc dot gnu.org> ---
All right, I've got a patch candidate:
https://gcc.gnu.org/pipermail/gcc-patches/2021-December/586999.html
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103696] pragma optimization is not applying to Lambdas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
` (3 preceding siblings ...)
2021-12-16 11:08 ` marxin at gcc dot gnu.org
@ 2021-12-16 16:52 ` cvs-commit at gcc dot gnu.org
2021-12-16 16:53 ` marxin at gcc dot gnu.org
2024-04-17 7:12 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-16 16:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:
https://gcc.gnu.org/g:5b8f5a50a93c5fd44fa1ecb6f431fee1df267571
commit r12-6018-g5b8f5a50a93c5fd44fa1ecb6f431fee1df267571
Author: Martin Liska <mliska@suse.cz>
Date: Wed Dec 15 17:27:56 2021 +0100
pragma: respect pragma in lambda functions
In g:01ad8c54fdca we started supporting target pragma changes
that are primarily caused by optimization option. The same can happen
in the opposite way and we need to check for changes both
in optimization_current_node and target_option_current_node.
PR c++/103696
gcc/ChangeLog:
* attribs.c (decl_attributes): Check if
target_option_current_node is changed.
gcc/testsuite/ChangeLog:
* g++.target/i386/pr103696.C: New test.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103696] pragma optimization is not applying to Lambdas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
` (4 preceding siblings ...)
2021-12-16 16:52 ` cvs-commit at gcc dot gnu.org
@ 2021-12-16 16:53 ` marxin at gcc dot gnu.org
2024-04-17 7:12 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-12-16 16:53 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Martin Liška <marxin at gcc dot gnu.org> ---
Fixed on master, not planning to backport as it depends on quite some
option-related patches that were done in GCC 12 timeframe.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug c++/103696] pragma optimization is not applying to Lambdas
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
` (5 preceding siblings ...)
2021-12-16 16:53 ` marxin at gcc dot gnu.org
@ 2024-04-17 7:12 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-17 7:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103696
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |12.0
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-04-17 7:12 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 20:30 [Bug target/103696] New: Lambda functions are not inlined under certain optimization pragmas imachug at gmail dot com
2021-12-13 20:33 ` [Bug target/103696] " imachug at gmail dot com
2021-12-14 1:14 ` [Bug c++/103696] pragma optimization is not applying to Lambdas pinskia at gcc dot gnu.org
2021-12-14 16:59 ` marxin at gcc dot gnu.org
2021-12-16 11:08 ` marxin at gcc dot gnu.org
2021-12-16 16:52 ` cvs-commit at gcc dot gnu.org
2021-12-16 16:53 ` marxin at gcc dot gnu.org
2024-04-17 7:12 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).