From patchwork Tue Nov 26 20:48:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 294408 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A920B2C007C for ; Wed, 27 Nov 2013 07:48:52 +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:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=g1jr1YrwWB34WWxBsz3Ha6Lkg1csli0CQVI3AIsc8yA lpJht2O3ht/Yw1ueq9IJoF9ZjyF/1N+I9mBUX9nfygRS54hsa3wftrHW9Eb5hq3C eGvGCKc8JXb2VgceBttAq4ve7EZfAX2utmAImkc9elPg6kY4HWSMA8N8bIOjcu8g = 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:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=xHayEMbQ68K4O2B5H6wX5R4qqhg=; b=nWcoFR4xnSPVD/pXY l1gRWNwqI3w5Vft+/gqp3aVo6s5M/FgNXEc+EsMPtx7Z9CoMnVU3u/29i2jrk0n3 Bu2ENgzMdlAzJ9GMZh4aardsGmi6RtcwLBjP8U299m+zG2g6Wz10TZB95pqlQ5NR egv/uuvtVbZ2hY2aYUcpXXgOTs= Received: (qmail 16739 invoked by alias); 26 Nov 2013 20:48:43 -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 16727 invoked by uid 89); 26 Nov 2013 20:48:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_50, RDNS_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from Unknown (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 26 Nov 2013 20:48:40 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAQKmX7N022435 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 26 Nov 2013 15:48:33 -0500 Received: from tucnak.zalov.cz (vpn1-4-96.ams2.redhat.com [10.36.4.96]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id rAQKmV6C013688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 26 Nov 2013 15:48:32 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id rAQKmVNi018849 for ; Tue, 26 Nov 2013 21:48:31 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id rAQKmUak018848 for gcc-patches@gcc.gnu.org; Tue, 26 Nov 2013 21:48:30 +0100 Date: Tue, 26 Nov 2013 21:48:30 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix simd reference reductions (PR middle-end/59150) Message-ID: <20131126204830.GQ892@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! The problem here is that lower_rec_input_clauses for privatized reference vars in clauses adds u = &u.1; statements, which is usually the right thing, but if this is a reduction in simd loop for which we are going to handle using simd arrays, then we want to set DECL_VALUE_EXPR of the var to something and having statement referencing such value in the IL is undesirable. Normally it will be removed as dead before expansion, but with a few disabled optimizations it can make it through to expansion and ICE there. Fixed by deferring addition of the u = &u.1; statement for references with reductions with placeholders. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2013-11-26 Jakub Jelinek PR middle-end/59150 * omp-low.c (lower_rec_input_clause): For reduction with placeholder of references to constant size types in simd loops, defer emitting initializer for the new_var, emit it later on only if not using SIMD arrays for it. * g++.dg/gomp/pr59150.C: New test. Jakub --- gcc/omp-low.c.jj 2013-11-26 14:20:46.000000000 +0100 +++ gcc/omp-low.c 2013-11-26 15:59:28.478863002 +0100 @@ -3185,15 +3185,26 @@ lower_rec_input_clauses (tree clauses, g } else if (TREE_CONSTANT (x)) { - const char *name = NULL; - if (DECL_NAME (var)) - name = IDENTIFIER_POINTER (DECL_NAME (new_var)); - - x = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_var)), - name); - gimple_add_tmp_var (x); - TREE_ADDRESSABLE (x) = 1; - x = build_fold_addr_expr_loc (clause_loc, x); + /* For reduction with placeholder in SIMD loop, + defer adding the initialization of the reference, + because if we decide to use SIMD array for it, + the initilization could cause expansion ICE. */ + if (c_kind == OMP_CLAUSE_REDUCTION + && OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) + && is_simd) + x = NULL_TREE; + else + { + const char *name = NULL; + if (DECL_NAME (var)) + name = IDENTIFIER_POINTER (DECL_NAME (new_var)); + + x = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (new_var)), + name); + gimple_add_tmp_var (x); + TREE_ADDRESSABLE (x) = 1; + x = build_fold_addr_expr_loc (clause_loc, x); + } } else { @@ -3201,8 +3212,11 @@ lower_rec_input_clauses (tree clauses, g x = build_call_expr_loc (clause_loc, atmp, 1, x); } - x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x); - gimplify_assign (new_var, x, ilist); + if (x) + { + x = fold_convert_loc (clause_loc, TREE_TYPE (new_var), x); + gimplify_assign (new_var, x, ilist); + } new_var = build_simple_mem_ref_loc (clause_loc, new_var); } @@ -3500,6 +3514,29 @@ lower_rec_input_clauses (tree clauses, g } break; } + /* If this is a reference to constant size reduction var + with placeholder, we haven't emitted the initializer + for it because it is undesirable if SIMD arrays are used. + But if they aren't used, we need to emit the deferred + initialization now. */ + else if (is_reference (var) && is_simd) + { + tree z + = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (new_vard))); + if (TREE_CONSTANT (z)) + { + const char *name = NULL; + if (DECL_NAME (var)) + name = IDENTIFIER_POINTER (DECL_NAME (new_vard)); + + z = create_tmp_var_raw + (TREE_TYPE (TREE_TYPE (new_vard)), name); + gimple_add_tmp_var (z); + TREE_ADDRESSABLE (z) = 1; + z = build_fold_addr_expr_loc (clause_loc, z); + gimplify_assign (new_vard, z, ilist); + } + } x = lang_hooks.decls.omp_clause_default_ctor (c, new_var, unshare_expr (x)); if (x) --- gcc/testsuite/g++.dg/gomp/pr59150.C.jj 2013-11-26 16:02:00.452084567 +0100 +++ gcc/testsuite/g++.dg/gomp/pr59150.C 2013-11-26 16:01:41.000000000 +0100 @@ -0,0 +1,25 @@ +// PR middle-end/59150 +// { dg-do compile } +// { dg-options "-O -fopenmp-simd -fno-tree-ccp -fno-tree-copy-prop -fno-tree-dce" } + +#pragma omp declare reduction (foo: int: omp_out += omp_in) initializer (omp_priv = 0) + +int +foo () +{ + int i, v, &u = v; + #pragma omp simd reduction (foo:u) + for (i = 0; i < 1024; i++) + u = i; + return u; +} + +int +bar () +{ + int i, v, &u = v; + #pragma omp simd reduction (foo:u) safelen(1) + for (i = 0; i < 1024; i++) + u = i; + return u; +}