public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kartikmohta at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [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
Date: Sun, 13 Dec 2020 23:11:02 +0000	[thread overview]
Message-ID: <bug-98265-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2020-12-13 23:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-13 23:11 kartikmohta at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98265-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).