From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27201 invoked by alias); 12 Mar 2008 17:34:13 -0000 Received: (qmail 27191 invoked by uid 22791); 12 Mar 2008 17:34:13 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Mar 2008 17:33:45 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m2CHXhaA023386; Wed, 12 Mar 2008 13:33:43 -0400 Received: from zebedee.pink (vpn-14-7.rdu.redhat.com [10.11.14.7]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m2CHXf6B019383; Wed, 12 Mar 2008 13:33:42 -0400 Message-ID: <47D813F5.2060301@redhat.com> Date: Wed, 12 Mar 2008 17:34:00 -0000 From: Andrew Haley User-Agent: Thunderbird 2.0.0.12 (X11/20080213) MIME-Version: 1.0 To: Lasse Kliemann CC: gcc-help@gcc.gnu.org Subject: Re: 4.3.0 strange problem with computation and optimization References: <20080312173125.GE2471@lasse.mail.plastictre.net> In-Reply-To: <20080312173125.GE2471@lasse.mail.plastictre.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2008-03/txt/msg00105.txt.bz2 Lasse Kliemann wrote: > Greetings, > > I have a C++ program that does some linear programming optimization. Out of > this linear programming, I get a vector of doubles `x' and a double `opt' > that should be the sum of the entries in `x' (`x' is the solution vector and > `opt' is the optimal value). As a consistency chek, I compute the sum of the > elements of `x' and then compute the difference to `opt'. It should be close > to zero. Here is a snippet from the code: > > double sum = 0; > const double *x = model->getColSolution(); > for (unsigned int j=0; j double d=opt-sum; > cout << "difference: " << d << endl; > > If I compile that with g++ version 4.3.0 and -O0, -O1, or -Os, everything > looks OK; in rare cases the difference is zero, and in most cases it is a > very small number. Now, if I compile that with -O2 or -O3, the difference is > *always* printed to be zero, which I presume is wrong. http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323\