From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8800 invoked by alias); 30 Dec 2014 11:53:29 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 8703 invoked by uid 48); 30 Dec 2014 11:53:24 -0000 From: "colin.pitrat+gcc at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/64442] New: -O1 modify output of a simple computation with rounding Date: Tue, 30 Dec 2014 11:53:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: colin.pitrat+gcc at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-12/txt/msg02928.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64442 Bug ID: 64442 Summary: -O1 modify output of a simple computation with rounding Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: colin.pitrat+gcc at gmail dot com When building the following program with -O1, it outputs 85 whereas without -O1 it outputs 84: #include #include int main() { double max = 8.03; double a = 6.01; double b = 5; double c = (double)0xFF / (max - b); int16_t value = (a - b) * c; printf("Result = %d\n", value); return 0; } The compilation lines I use are really minimal: - gcc main.c vs - gcc -O1 main.c I tried to find which optimization flag was producing this issue but couldn't find any ! - I don't have the issue when I don't use -O1 but provide explicitely all (or any of) -O1 optimization flags (obtained with gcc -Q -O1 --help=optimizers | grep "\-f" | grep enabled | awk '{ print $1 }' | xargs) - Among all optimizer flags, I have the same issue only when providing either -fsingle-precision-constant, -ffloat-store or -fshort-double but those flags are supposed to be deactivated in -O1 Note that I didn't test -fpack-struct because it didn't build Regards, Colin