From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3896 invoked by alias); 5 Apr 2008 13:01:10 -0000 Received: (qmail 3886 invoked by uid 22791); 5 Apr 2008 13:01:10 -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; Sat, 05 Apr 2008 13:00:52 +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 m35D0fiw012364; Sat, 5 Apr 2008 09:00:41 -0400 Received: from zebedee.pink (vpn-14-16.rdu.redhat.com [10.11.14.16]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m35D0cMs031062; Sat, 5 Apr 2008 09:00:39 -0400 Message-ID: <47F777F6.5060809@redhat.com> Date: Sat, 05 Apr 2008 13:07:00 -0000 From: Andrew Haley User-Agent: Thunderbird 2.0.0.12 (X11/20080213) MIME-Version: 1.0 To: tprince@computer.org CC: Christian Keil , gcc-help@gcc.gnu.org Subject: Re: Floating point optimizations References: <47F50A75.6070801@tu-harburg.de> <20080403172718.GA4451@endeed2.ispras.ru> <47F6D132.6010603@sbcglobal.net> In-Reply-To: <47F6D132.6010603@sbcglobal.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-04/txt/msg00062.txt.bz2 Tim Prince wrote: > Alexander Monakov wrote: >>> we are currently investigating some numerical algorithms and the claim >>> appeared that a C statement like >>> x = c - (c - a); >>> would be easily transformed into >>> x = a; >>> by the compiler. Now investigating this with a vanilla GCC 4.1.2 failed >>> to support the claim. Compiling the below program with -O3 -ffast-math >>> keeps the computation of x. The output shows x is different from a. The >>> question is, is there some compiler switch or the like to get GCC to >>> make the above transformation? I searched the docs but had the >>> impression that all relevant flags should be included in the above two >>> (especially ffast-math). >> >> This transformation is indeed included into -ffast-math. I checked with >> >> $ gcc --version >> gcc (GCC) 4.1.1 20070105 (Red Hat 4.1.1-52) >> >> and it does eliminate the calculation. What does generated assembly >> code look >> like in your case? Note you may as well check on this code: >> >> double f(double a, double c) >> { >> > Normally, when such expressions are written in source code, there is a > reasonable expectation that algebraic simplification will not be > performed across parentheses. There may well be such an expectation, but gcc only prevents re-association across explicit parenthesis in FORTRAN, and it's only been doing that for a few weeks. Andrew.