From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15805 invoked by alias); 10 Jan 2012 16:28:14 -0000 Received: (qmail 15785 invoked by uid 22791); 10 Jan 2012 16:28:13 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Tue, 10 Jan 2012 16:28:01 +0000 From: "aph at gcc dot gnu.org" To: java-prs@gcc.gnu.org Subject: [Bug java/21855] array bounds checking elimination Date: Tue, 10 Jan 2012 16:28:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: java X-Bugzilla-Keywords: alias, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: aph at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: dnovillo 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 java-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-prs-owner@gcc.gnu.org X-SW-Source: 2012-q1/txt/msg00007.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21855 --- Comment #16 from Andrew Haley 2012-01-10 16:26:51 UTC --- (In reply to comment #15) > (In reply to comment #14) > > (In reply to comment #13) > > > We can't optimize this because System.out.println can change args[]. > > > > That's the whole point: System.out.println cannot change args[], which is a > > java array, and the length of a Java array is constant. It is not an invalid > > test case. > > I suppose > > public static void main(String[] args) > > is passing args by value (but the implementation detail uses reference > passing for efficiency?). args is indeed a reference to a Java array. The length field of a Java array is immutable. The elements of an array are not immutable. > In this case the Java frontend should do > like the C++ frontend and tell this to the middle-end by properly > marking args as 1) DECL_BY_REFERENCE, 2) use a TYPE_RESTRICT qualified > pointer for the reference. Then we would optimize this case. If we could mark the length field as immutable that would fix it. Is there any way to do that?