public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug ipa/98265] New: gcc-10 has significantly worse code generated with -O2 compared to -O1 (or gcc-9 -O2) when using the Eigen C++ library
@ 2020-12-13 23:11 kartikmohta at gmail dot com
  2020-12-13 23:12 ` [Bug ipa/98265] " kartikmohta at gmail dot com
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: kartikmohta at gmail dot com @ 2020-12-13 23:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98265

            Bug ID: 98265
           Summary: gcc-10 has significantly worse code generated with -O2
                    compared to -O1 (or gcc-9 -O2) when using the Eigen
                    C++ library
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kartikmohta at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

I was checking the generated assembly for the following simple code using the
Eigen C++ library:

#include <Eigen/Core>

Eigen::Matrix<float, 3, 1> f(float x, float y, float z, float scale)
{
  return Eigen::Matrix<float, 3, 1>(x, y, z) * scale;
}

The Eigen::Matrix structure can be thought of as just a wrapper around an array
in this case. The preprocessed file is attached.


When compiled with -O1 optimization, this generates the expected reasonable
looking code, but when using -O2 it looks like the generated code is extremely
bad. The code generated by gcc-9.3 with -O2 also looks good. A quick comparison
of the code generated by gcc 10.2 vs gcc 9.3 can be seen at
https://godbolt.org/z/186c19.


Upon bisecting this, it seems like the offending changes are from the pair of
commits which changed some of the inliner params:

commit 1e83bd7003e03160b7d71fb959111e89b53446ab
Author: Jan Hubicka <hubicka@gcc.gnu.org>
Date:   Sat Nov 23 05:13:23 2019

    Convert inliner to new param infrastructure

commit 9340d34599e6d5e7a6f3614de44b2c578b180c1b
Author: Jan Hubicka <hubicka@ucw.cz>
Date:   Sat Nov 23 05:11:25 2019

    Convert inliner to function specific param infrastructure


By playing with the optimization parameters, I saw that using either
-fno-partial-inlining or --param early-inlining-insns=14 fixes the generated
code with -O2.

Upon further investigation, it looks like earlier there were two separate
params for early-inlining-insns for -O3 and -O2 but in the consider_split
function (ipa-split.c) only the value for -O3 was used irrespective of the
optimization level. This code was not changed when the inliner params changes
were made leading to a much smaller value of param_early_inlining_insns being
used in consider_split for -O2 now, which may be causing problems with inlining
in this case.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-09-05 17:54 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-13 23:11 [Bug ipa/98265] New: gcc-10 has significantly worse code generated with -O2 compared to -O1 (or gcc-9 -O2) when using the Eigen C++ library kartikmohta at gmail dot com
2020-12-13 23:12 ` [Bug ipa/98265] " kartikmohta at gmail dot com
2021-01-04 14:29 ` [Bug ipa/98265] [10/11 Regression] " rguenth at gcc dot gnu.org
2021-01-11 21:47 ` kartikmohta at gmail dot com
2021-01-12  9:40 ` marxin at gcc dot gnu.org
2021-01-12  9:40 ` marxin at gcc dot gnu.org
2021-01-14 11:07 ` rguenth at gcc dot gnu.org
2021-02-14 22:47 ` hubicka at gcc dot gnu.org
2021-02-14 22:50 ` hubicka at gcc dot gnu.org
2021-03-31 20:45 ` cvs-commit at gcc dot gnu.org
2021-03-31 20:47 ` cvs-commit at gcc dot gnu.org
2021-04-01 10:12 ` cvs-commit at gcc dot gnu.org
2021-04-01 10:14 ` hubicka at gcc dot gnu.org
2021-04-09 10:42 ` [Bug ipa/98265] [10 " rguenth at gcc dot gnu.org
2021-04-09 12:01 ` rguenth at gcc dot gnu.org
2021-04-10 11:07 ` schwab@linux-m68k.org
2021-04-15  9:54 ` hubicka at gcc dot gnu.org
2021-09-05 17:54 ` 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).