public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/95859] New: Statically true asserts not recognized as such with -O2, but with -O1, -Og, -O3
@ 2020-06-24  7:28 tobi at gcc dot gnu.org
  2020-06-24  7:51 ` [Bug ipa/95859] " rguenth at gcc dot gnu.org
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: tobi at gcc dot gnu.org @ 2020-06-24  7:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95859
           Summary: Statically true asserts not recognized as such with
                    -O2, but with -O1, -Og, -O3
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tobi at gcc dot gnu.org
  Target Milestone: ---

With -O2 compiling for x86-64, the compiler doesn't recognize that a number of
assertions in the code are true and they end up as function calls in the
assembly output.  They are removed with -O1, -Og, -O3 but not with -O2 or -O2 +
"all the additional compiler flags for -O3 given in the documentation" (that's
a documentation bug on top of this misoptimization).

The asserts look something like this in the assembled form:
   template <N>
   assertion(int n) {
      assert(n == N);
   }
and are only called with compile-time constant arguments, i.e. assertion<3>(3)
and the like.

The final output from the tree passes contains the assertion calls at all
optimization levels, so the rtl optimizers appear to perform worst in -O2 in
this particular case.  I don't see why the calls couldn't be removed before
lowering to RTL.

I'm not sure how to extract preprocessed output form the compiler explorer, but
will provide it once I can put my hands on a recent gcc.

Source code reproduced below, the compiler explorer link is here:
https://godbolt.org/z/REJDhy

#include <Eigen/Geometry>

struct m34 {
    float m[3][4];
};
typedef Eigen::Transform<double, 3, Eigen::AffineCompact, Eigen::DontAlign>
unalignedTrafo3d;
using Trafo3d = unalignedTrafo3d;


Trafo3d func34(m34 mat)
{
    using mapType = Eigen::Map<Eigen::Matrix<float, 3, 4, Eigen::RowMajor>>;

    // should compile to a conversion of 12 floats to double.
    auto mR = Trafo3d{ mapType{ (float*)mat.m }.cast<double>() };
    return mR;    
}

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

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

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24  7:28 [Bug rtl-optimization/95859] New: Statically true asserts not recognized as such with -O2, but with -O1, -Og, -O3 tobi at gcc dot gnu.org
2020-06-24  7:51 ` [Bug ipa/95859] " rguenth at gcc dot gnu.org
2020-06-24 14:42 ` tobi at gcc dot gnu.org
2020-06-24 15:02 ` tobi at gcc dot gnu.org
2020-06-25  9:00 ` tobi at gcc dot gnu.org
2020-07-07  7:08 ` [Bug ipa/95859] [10/11 regression] " tobi at gcc dot gnu.org
2020-07-07  7:09 ` tobi at gcc dot gnu.org
2020-07-15  6:50 ` rguenth at gcc dot gnu.org
2020-07-23  6:51 ` rguenth at gcc dot gnu.org
2020-07-25 12:37 ` tobi at gcc dot gnu.org
2020-10-12 12:53 ` rguenth at gcc dot gnu.org
2021-02-25 11:08 ` jakub at gcc dot gnu.org
2021-03-10 20:04 ` jakub at gcc dot gnu.org
2021-04-02  2:04 ` tobi at gcc dot gnu.org
2021-04-02  2:07 ` tobi at gcc dot gnu.org
2021-04-05  2:35 ` tobi at gcc dot gnu.org
2021-04-08 12:02 ` rguenth at gcc dot gnu.org
2021-06-29  2:39 ` [Bug ipa/95859] [10/11/12 " tobi 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).