public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/64442] New: -O1 modify output of a simple computation with rounding
@ 2014-12-30 11:53 colin.pitrat+gcc at gmail dot com
  2014-12-30 15:44 ` [Bug c/64442] " colin.pitrat+gcc at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: colin.pitrat+gcc at gmail dot com @ 2014-12-30 11:53 UTC (permalink / raw)
  To: gcc-bugs

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 <stdio.h>
#include <stdint.h>

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


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

* [Bug c/64442] -O1 modify output of a simple computation with rounding
  2014-12-30 11:53 [Bug c/64442] New: -O1 modify output of a simple computation with rounding colin.pitrat+gcc at gmail dot com
@ 2014-12-30 15:44 ` colin.pitrat+gcc at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: colin.pitrat+gcc at gmail dot com @ 2014-12-30 15:44 UTC (permalink / raw)
  To: gcc-bugs

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

Colin Pitrat <colin.pitrat+gcc at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Colin Pitrat <colin.pitrat+gcc at gmail dot com> ---
OK thank you, sorry for the bothering !

In the mean time I also discovered -Og that appeared in gcc 4.8, that provides
optimization compatible with debugging and that have the same behavior. This
allows me to have the same result with the release and the debug build, which
is what was the issue for me.

I'm still surprised by the fact that -Og or -O1 seems to be more than just the
list of -f flags it activates, as providing only them doesn't trigger this same
behaviour. I couldn't find another responsible flag in the difference I found
in the output of --help=warnings,target,params,c or common

Closing this bug as invalid.

Regards,
Colin


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

end of thread, other threads:[~2014-12-30 15:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-30 11:53 [Bug c/64442] New: -O1 modify output of a simple computation with rounding colin.pitrat+gcc at gmail dot com
2014-12-30 15:44 ` [Bug c/64442] " colin.pitrat+gcc at gmail dot com

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).