From patchwork Wed Mar 20 21:59:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 229504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "localhost", Issuer "www.qmailtoaster.com" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 76B532C00BD for ; Thu, 21 Mar 2013 09:00:08 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; q=dns; s=default; b=S8qAQ9tu+Szeq86/Y Ox3K0LoUBuHy/hgvLTfp+I2hkZw80jYKFgIHBZ9Krym2sQlG76gsjdY25xbBPGM+ EX6GqEqSGKHks/eWCoYUdCFM71batRQOL5CBOcfSZBFmvz4xfdo6j8bsRqBSMs9E idmnZnI0bLZuHz1wnl/J0urFiU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:references :in-reply-to:content-type; s=default; bh=B/nL1NVcg3YqJobn1mXl4F0 gFzc=; b=xJuvGqkpA/suMGqAxxdfpLWk49XXM3C0sQTNOd8jp3myEWmyIZGbZ3C ZKnlIOVlXkpFIqgvbCrJk9yboymV1llMDZdm6l9QepbayjX8Nw3GMh/c9nX0wyQw aJwea7DcfilgTsvC1pO3755vbdfVC1KzSBYUI+SMn3U/gzYfEemo= Received: (qmail 18752 invoked by alias); 20 Mar 2013 22:00:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 18680 invoked by uid 89); 20 Mar 2013 21:59:55 -0000 X-Spam-SWARE-Status: No, score=-8.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.1 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 20 Mar 2013 21:59:52 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2KLxnvG016166 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 20 Mar 2013 17:59:49 -0400 Received: from houston.quesejoda.com (vpn-58-77.rdu2.redhat.com [10.10.58.77]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r2KLxml5027695; Wed, 20 Mar 2013 17:59:48 -0400 Message-ID: <514A3153.6040707@redhat.com> Date: Wed, 20 Mar 2013 16:59:47 -0500 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130311 Thunderbird/17.0.4 MIME-Version: 1.0 To: "Joseph S. Myers" CC: "Iyer, Balaji V" , gcc-patches Subject: [cilkplus-merge] test for side effects References: <5149D62F.9070503@redhat.com> In-Reply-To: <5149D62F.9070503@redhat.com> > I have found some little nits that I will point out in a reply to this > message. Balaji: In Joseph's review on October 19, 2012 (http://gcc.gnu.org/ml/gcc-patches/2012-10/msg01838.html) he mentioned: > Say expr1 through expr9 are expressions with side effects, and you have: > > expr1[expr2:expr3:expr4] = expr5[expr6:expr7:expr8] + expr9; > > The spec says "However, in such a statement, a sub-expression with rank > zero is evaluated only once." - that is, each of the nine expressions is > evaluated once. I don't see any calls to save_expr to ensure these > semantics, or any testcases that verify that they are adhered to. If I understand Joseph's comment, this is still broken on the branch. For example, in the example below: array[func1() + 11 : func2() + 22 : func3() + 33] = 666; ...the function calls should only be called once, yet currently we generate: D.1739 = 0; : D.1769 = func2 (); D.1770 = D.1769 + 22; if (D.1739 < D.1770) goto ; else goto ; : D.1771 = func1 (); <-- BOO HISS D.1772 = D.1771 + 11; D.1773 = func3 (); <-- BOO HISS D.1774 = D.1773 + 33; D.1775 = D.1739 * D.1774; D.1776 = D.1772 + D.1775; array[D.1776] = 666; D.1739 = D.1739 + 1; goto ; : As you can see, func1() and func3() are being called repeatedly within the loop. I am adding the attached execute test to the harness. If my understanding is correct, this test should pass. Joseph, please let me know if I misunderstood things in some way. Committed to cilkplus-merge branch. commit 4447dcf380a08f74bf5b91fd84d7013cbbb34ee8 Author: Aldy Hernandez Date: Wed Mar 20 16:47:02 2013 -0500 Add new test to verify that the array index, limit, and stride are only evaluated once. diff --git a/gcc/testsuite/gcc.dg/cilk-plus/array_notation/execute/side-effects-1.c b/gcc/testsuite/gcc.dg/cilk-plus/array_notation/execute/side-effects-1.c new file mode 100644 index 0000000..1845862 --- /dev/null +++ b/gcc/testsuite/gcc.dg/cilk-plus/array_notation/execute/side-effects-1.c @@ -0,0 +1,23 @@ +/* Test that the array index, limit, and stride are evaluated only + once. */ + +int array[1000]; + +int func1_times = 0; +int func2_times = 0; +int func3_times = 0; +int func1() { func1_times++; return 0; } +int func2() { func2_times++; return 0; } +int func3() { func3_times++; return 0; } + +int main() +{ + array[func1() + 11 : func2() + 22 : func3() + 33] = 666; + + if (func1_times != 1 + || func2_times != 1 + || func3_times != 1) + abort(); + + return 0; +}