From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23407 invoked by alias); 31 May 2002 10:06:06 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 23385 invoked by uid 71); 31 May 2002 10:06:03 -0000 Resent-Date: 31 May 2002 10:06:03 -0000 Resent-Message-ID: <20020531100603.23384.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, rguenth@tat.physik.uni-tuebingen.de Received:(qmail 22508 invoked by uid 61); 31 May 2002 10:00:37 -0000 Message-Id:<20020531100036.22507.qmail@sources.redhat.com> Date: Fri, 31 May 2002 03:46:00 -0000 From: rguenth@tat.physik.uni-tuebingen.de Reply-To: rguenth@tat.physik.uni-tuebingen.de To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/6883: Fails to optimize temporary objects. X-SW-Source: 2002-05/txt/msg01016.txt.bz2 List-Id: >Number: 6883 >Category: optimization >Synopsis: Fails to optimize temporary objects. >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: pessimizes-code >Submitter-Id: net >Arrival-Date: Fri May 31 03:06:02 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Richard Guenther >Release: gcc version 3.1.1 20020516 (prerelease) >Organization: >Environment: Linux bellatrix 2.4.18-rc4-TATUP #2 Tue Mar 19 16:30:05 CET 2002 i686 unknown >Description: Temporary objects are not optimized away, which is a serious problem for medium-complex iterators. See attachment for an example. The first loop body which uses temporary objects compiles (ix86, -O3 -fno-exceptions) to movl -88(%ebp), %ecx movl -80(%ebp), %eax movl -140(%ebp), %esi movl %ecx, -104(%ebp) movl -56(%ebp), %ebx leal 0(,%eax,8), %edx movl %ecx, -120(%ebp) movl -40(%ebp), %edi movl -140(%ebp), %ecx movl %esi, -100(%ebp) leal -1(%eax), %esi incl %eax movl %eax, -112(%ebp) addl %edx, %edi movl %esi, -96(%ebp) movl %ecx, -116(%ebp) fldl (%ebx,%eax,8) movl -72(%ebp), %eax faddl (%ebx,%esi,8) addl %eax, %edx fmull (%edx) fstpl (%edi) which fails to optimize the created temporary objects. It should be optimized to the equivalent code for the second implementation manually doing this optimization: movl -128(%ebp), %edi movl -56(%ebp), %eax movl -40(%ebp), %esi movl -72(%ebp), %ecx leal 0(,%edi,8), %ebx addl %ebx, %esi fldl 8(%eax,%edi,8) addl %ecx, %ebx faddl -8(%eax,%edi,8) fmull (%ebx) fstpl (%esi) This problem pessimizes code which uses iterators like that by about a factor of 3 compared to equivalent C code which is a serious problem. >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: text/plain; name="iterator-gnats.cpp" Content-Disposition: inline; filename="iterator-gnats.cpp" class Iterator { public: Iterator(int i0, int i1) : m_i0(i0), m_i1(i1) { m_i = i0; } Iterator operator+(int i) const { Iterator it(*this); it.m_i += i; return it; } Iterator operator-(int i) const { Iterator it(*this); it.m_i -= i; return it; } bool operator++() { m_i++; if (m_i > m_i1) return false; return true; } int getIndex() const { return m_i; } private: const int m_i0, m_i1; int m_i; }; class Array { public: Array(int size) : m_v(new double(size)) {} ~Array() { delete m_v; } double& operator()(const Iterator& i) { return m_v[i.getIndex()]; } double& operator()(const Iterator& i, int d) { return m_v[i.getIndex()+d]; } private: double * const m_v; }; int main(int argc, char **argv) { Array a(256); Array b(256); Array c(256); // temporary objects not optimized { Iterator i(1, 254); do { a(i) = (b(i-1)+b(i+1))*c(i); } while (++i); } // optimized ok { Iterator i(1, 254); do { a(i) = (b(i,-1)+b(i,+1))*c(i); } while (++i); } }