From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23437 invoked by alias); 7 Jun 2012 15:25:57 -0000 Received: (qmail 23416 invoked by uid 22791); 7 Jun 2012 15:25:53 -0000 X-SWARE-Spam-Status: No, hits=-4.3 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Jun 2012 15:25:41 +0000 From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/52861] (missed optimisation) missed transformation to memset with -O3 Date: Thu, 07 Jun 2012 15:25:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: minor X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: tkoenig at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2012-06/txt/msg00411.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52861 --- Comment #7 from Tobias Burnus 2012-06-07 15:25:37 UTC --- Created attachment 27579 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27579 Proof-of-concept patch (works but has many regression-test failures) (In reply to comment #5) > Fixed on trunk, closing. Well, not completely - only for the special case. I think there is more room for improvement: Hoisting the memset out of the loop and using ARRAY_RANGE_REF for the assignments. * * * The attach patch contains a proof-of-concept implementation of ARRAY_RANGE_REF. The problem is that one needs to strip off several operations on the LHS/RHS in order to use ARRAY_RANGE_REF. For instance, for a literal, one gets *&"abcd"[1] but the bare "abcd" is needed (note the ARRAY_REF "[1]"); but one needs to have just the literal "abcd". For "var(2:0)" one not only needs to strip off the ARRAY_REF, but one also needs to obtain the offset. While for "string(1)(:)" and "string(1)(2:3)" the ARRAY_REF for the array has to be kept, but not for the string part (except for the lower bound). The current version is rather hacky :-( Additionally, one runs into the problem that a pointer to a "char" and a pointer to a "char[:]" aren't the same; many temporary vars have the wrong kind of "char" type. While the code works rather nicely for various small test cases, there are many test-suite failures with the patch. The problem is simply that removing the (sub)string ARRAY_REF while keeping the array ARRAY_REF is difficult. Fixing the arguments to gfc_trans_string_copy is also not that simple. Example for a failing test case: character(len=4, kind=1),pointer :: str(:) allocate(str(1)) str(1) = 1_"abcd" ! Fails str(1)(2:) = 1_"abcd" ! Works