From patchwork Fri Dec 13 10:13:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Schwinge X-Patchwork-Id: 300977 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 97BFF2C00A1 for ; Fri, 13 Dec 2013 21:13:24 +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:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; q=dns; s=default; b=PWPZl46DA4TNsQVZ O85tHqGe5CJqUjTwbNFdwXXXS1MPM7TkLIYpZMh8/zCz5hFZCkxhz/sbnr/cPkGH Nd4WVvFPBbwxq769hbnhiPD4LkBwMiioQJvek9kUR8ZGoeexmXCd6N2/qRGg9EiQ KgJbwEct0kL6xpdfW4yDwrWhXEQ= 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:from :to:cc:subject:in-reply-to:references:date:message-id :mime-version:content-type; s=default; bh=nZ6oBbnCwEfyKYbi11HgcN 6q/F4=; b=t6Z/14aah4S1dwX8d8c8P31U+D+274/KQf00xYArMsITqUvLqgQNOk ogkYPjgR+7FXAfbPKcYwTPh74axMlaNAkNlV1C2IGrX+cExovi6ctuWK0pv84cfv 4y8vagh+rgCMQLTPRxZ281wy8jdEKmTFVig3+sHWuZvalJKuST75Y= Received: (qmail 19289 invoked by alias); 13 Dec 2013 10:13:18 -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 19278 invoked by uid 89); 13 Dec 2013 10:13:17 -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_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 13 Dec 2013 10:13:16 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1VrPk8-0002fw-TP from Thomas_Schwinge@mentor.com ; Fri, 13 Dec 2013 02:13:12 -0800 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 13 Dec 2013 02:13:12 -0800 Received: from feldtkeller.schwinge.homeip.net (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.2.247.3; Fri, 13 Dec 2013 10:13:10 +0000 From: Thomas Schwinge To: Jakub Jelinek CC: , Richard Henderson , "Michael V. Zolotukhin" Subject: maybe_fold_stmt (was: [gomp4] #pragma omp target* fixes) In-Reply-To: <20130905161105.GL23437@tucnak.redhat.com> References: <20130905161105.GL23437@tucnak.redhat.com> User-Agent: Notmuch/0.9-101-g81dad07 (http://notmuchmail.org) Emacs/23.4.1 (i486-pc-linux-gnu) Date: Fri, 13 Dec 2013 11:13:03 +0100 Message-ID: <8761qtrrdc.fsf@kepler.schwinge.homeip.net> MIME-Version: 1.0 Hi! On Thu, 5 Sep 2013 18:11:05 +0200, Jakub Jelinek wrote: > 4) the reference testcase showed a problem with fold_stmt calls > we do very early, during gimplification, because for TREE_READONLY > vars with DECL_INITIAL fold_stmt can replace the uses of the var with > its initializer, but as the gimplifier isn't aware of it, we wouldn't remap > that, or worse there could be explicit remapping of it via array section, > but one that the compiler doesn't see, and if that is smaller than > the whole array size, that would result in runtime error. So, after > some talk with richi on IRC, I've decided to just not fold_stmt > inside of target constructs during gimplification and defer it until > omplower. > * gimplify.c (gimplify_call_expr): Don't call fold_stmt > inside of #pragma omp target construct. > (gimplify_modify_expr): Likewise. > * omp-low.c > (lower_omp): Call fold_stmt on all stmts inside of > #pragma omp target construct. > --- gcc/gimplify.c.jj 2013-09-05 09:19:03.000000000 +0200 > +++ gcc/gimplify.c 2013-09-05 14:45:48.632720617 +0200 > @@ -2704,7 +2704,14 @@ gimplify_call_expr (tree *expr_p, gimple > notice_special_calls (call); > gimplify_seq_add_stmt (pre_p, call); > gsi = gsi_last (*pre_p); > - fold_stmt (&gsi); > + /* Don't fold stmts inside of target construct. We'll do it > + during omplower pass instead. */ > + struct gimplify_omp_ctx *ctx; > + for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) > + if (ctx->region_type == ORT_TARGET) > + break; > + if (ctx == NULL) > + fold_stmt (&gsi); > *expr_p = NULL_TREE; > } > else > @@ -4961,7 +4968,14 @@ gimplify_modify_expr (tree *expr_p, gimp > > gimplify_seq_add_stmt (pre_p, assign); > gsi = gsi_last (*pre_p); > - fold_stmt (&gsi); > + /* Don't fold stmts inside of target construct. We'll do it > + during omplower pass instead. */ > + struct gimplify_omp_ctx *ctx; > + for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) > + if (ctx->region_type == ORT_TARGET) > + break; > + if (ctx == NULL) > + fold_stmt (&gsi); > > if (want_value) > { > --- gcc/omp-low.c.jj 2013-09-05 09:19:03.000000000 +0200 > +++ gcc/omp-low.c 2013-09-05 17:11:14.693638660 +0200 > @@ -9673,6 +9685,12 @@ lower_omp (gimple_seq *body, omp_context > gimple_stmt_iterator gsi; > for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi)) > lower_omp_1 (&gsi, ctx); > + /* Inside target region we haven't called fold_stmt during gimplification, > + because it can break code by adding decl references that weren't in the > + source. Call fold_stmt now. */ > + if (target_nesting_level) > + for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi)) > + fold_stmt (&gsi); > input_location = saved_location; > } OK to commit to trunk the following patch? commit 6ff10eb51ea39a25e53e0369626559be208bb16e Author: Thomas Schwinge Date: Mon Oct 21 16:37:41 2013 +0200 Refactor common code into new maybe_fold_stmt function. gcc/ * gimplify.c (gimplify_call_expr, gimplify_modify_expr): Move common code... (maybe_fold_stmt): ... into this new function. * omp-low.c (lower_omp): Update comment. Grüße, Thomas diff --git gcc/gimplify.c gcc/gimplify.c index 1ca847a..7203456 100644 --- gcc/gimplify.c +++ gcc/gimplify.c @@ -2184,6 +2184,23 @@ gimplify_arg (tree *arg_p, gimple_seq *pre_p, location_t call_location) return gimplify_expr (arg_p, pre_p, NULL, test, fb); } +/* Don't fold STMT inside ORT_TARGET, because it can break code by adding decl + references that weren't in the source. We'll do it during omplower pass + instead. */ + +static bool +maybe_fold_stmt (gimple_stmt_iterator *gsi) +{ + bool changed = false; + struct gimplify_omp_ctx *ctx; + for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) + if (ctx->region_type == ORT_TARGET) + break; + if (ctx == NULL) + changed = fold_stmt (gsi); + return changed; +} + /* Gimplify the CALL_EXPR node *EXPR_P into the GIMPLE sequence PRE_P. WANT_VALUE is true if the result of the call is desired. */ @@ -2417,14 +2434,7 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value) notice_special_calls (call); gimplify_seq_add_stmt (pre_p, call); gsi = gsi_last (*pre_p); - /* Don't fold stmts inside of target construct. We'll do it - during omplower pass instead. */ - struct gimplify_omp_ctx *ctx; - for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) - if (ctx->region_type == ORT_TARGET) - break; - if (ctx == NULL) - fold_stmt (&gsi); + maybe_fold_stmt (&gsi); *expr_p = NULL_TREE; } else @@ -4572,14 +4582,7 @@ gimplify_modify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, gimplify_seq_add_stmt (pre_p, assign); gsi = gsi_last (*pre_p); - /* Don't fold stmts inside of target construct. We'll do it - during omplower pass instead. */ - struct gimplify_omp_ctx *ctx; - for (ctx = gimplify_omp_ctxp; ctx; ctx = ctx->outer_context) - if (ctx->region_type == ORT_TARGET) - break; - if (ctx == NULL) - fold_stmt (&gsi); + maybe_fold_stmt (&gsi); if (want_value) { diff --git gcc/omp-low.c gcc/omp-low.c index 05fca40..1222df6 100644 --- gcc/omp-low.c +++ gcc/omp-low.c @@ -10110,9 +10110,8 @@ lower_omp (gimple_seq *body, omp_context *ctx) gimple_stmt_iterator gsi; for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi)) lower_omp_1 (&gsi, ctx); - /* Inside target region we haven't called fold_stmt during gimplification, - because it can break code by adding decl references that weren't in the - source. Call fold_stmt now. */ + /* During gimplification, we haven't called fold_stmt inside ORT_TARGET + (gimplify.c:maybe_fold_stmt); call it now. */ if (target_nesting_level) for (gsi = gsi_start (*body); !gsi_end_p (gsi); gsi_next (&gsi)) fold_stmt (&gsi);