This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/81906] New: Calls to rint() wrongly optimized away starting in g++ 6


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

            Bug ID: 81906
           Summary: Calls to rint() wrongly optimized away starting in g++
                    6
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vz-gcc at zeitlins dot org
  Target Milestone: ---

Here is a test case:

---------------------------------- >8 --------------------------------------
#include <cfenv>
#include <cmath>
#include <stdio.h>

int main()
{
    printf("--- Test built with gcc %d.%d.%d ---\n",
           __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__ );

    auto const x = -2.5;

    printf("Default round mode : rint(%g)=%g\n", x, std::rint(x));
    fesetround(FE_DOWNWARD);
    printf("Downward round mode: rint(%g)=%g\n", x, std::rint(x));

    return 0;
}
---------------------------------- >8 --------------------------------------

% g++-7 -O1 -Wall -std=c++11 rint.cpp && ./a.out
--- Test built with gcc 7.1.0 ---
Default round mode : rint(-2.5)=-2
Downward round mode: rint(-2.5)=-2

Replacing -O1 with -O0 yields the expected -3 in the last line, but with -O1
(and -O2 etc), the second call to rint() is completely eliminated as can be
seen by examining the generated assembly.

The same bug is also present in 6.4.0 but not in 5.4.1 nor previous versions,
so it looks like rint() has somehow become marked as pure in gcc 6.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]