public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Bernd Schmidt <bschmidt@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Richard Guenther <richard.guenther@gmail.com>
Subject: Re: [OpenACC] internal fn folding
Date: Thu, 05 Nov 2015 15:48:00 -0000	[thread overview]
Message-ID: <563B7A32.7010209@acm.org> (raw)
In-Reply-To: <5639D79B.8040200@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

On 11/04/15 05:02, Bernd Schmidt wrote:
> On 11/02/2015 02:56 PM, Nathan Sidwell wrote:
>> On 10/28/15 14:40, Nathan Sidwell wrote:
>>> Richard,
>>> this patch adds folding for the new GOACC_DIM_POS and GOACC_DIM_SIZE
>>> internal
>>> functions.  IIUC gimple_fold_call is the right place to add this.
>>>
>>> The size of a compute dimension is very often a compile-time
>>> constant.  On the
>>> host, in particular it's 1, which means we can deduce the POS must be
>>> zero.
>>>
>>> ok?

This is what I committed, using the helpers I recently added. (I realized we can 
only get here for functions with the oacc attribute already set)

nathan

[-- Attachment #2: trunk-dim-fold-1105.patch --]
[-- Type: text/x-patch, Size: 1777 bytes --]

2015-11-05  Nathan Sidwell  <nathan@codesourcery.com>

	* gimple-fold.c: Include omp-low.h.
	(fold_internal_goacc_dim): New.
	(gimple_fold_call): Call it.

Index: gimple-fold.c
===================================================================
--- gimple-fold.c	(revision 229809)
+++ gimple-fold.c	(working copy)
@@ -52,6 +52,7 @@ along with GCC; see the file COPYING3.
 #include "gimple-match.h"
 #include "gomp-constants.h"
 #include "optabs-query.h"
+#include "omp-low.h"
 
 
 /* Return true when DECL can be referenced from current unit.
@@ -2906,6 +2907,28 @@ gimple_fold_builtin (gimple_stmt_iterato
   return false;
 }
 
+/* Transform IFN_GOACC_DIM_SIZE and IFN_GOACC_DIM_POS internal
+   function calls to constants, where possible.  */
+
+static tree
+fold_internal_goacc_dim (const gimple *call)
+{
+  int axis = get_oacc_ifn_dim_arg (call);
+  int size = get_oacc_fn_dim_size (current_function_decl, axis);
+  bool is_pos = gimple_call_internal_fn (call) == IFN_GOACC_DIM_POS;
+  tree result = NULL_TREE;
+
+  /* If the size is 1, or we only want the size and it is not dynamic,
+     we know the answer.  */
+  if (size == 1 || (!is_pos && size))
+    {
+      tree type = TREE_TYPE (gimple_call_lhs (call));
+      result = build_int_cst (type, size - is_pos);
+    }
+
+  return result;
+}
+
 /* Return true if ARG0 CODE ARG1 in infinite signed precision operation
    doesn't fit into TYPE.  The test for overflow should be regardless of
    -fwrapv, and even for unsigned types.  */
@@ -3106,6 +3129,10 @@ gimple_fold_call (gimple_stmt_iterator *
 	      return true;
 	    }
 	  break;
+	case IFN_GOACC_DIM_SIZE:
+	case IFN_GOACC_DIM_POS:
+	  result = fold_internal_goacc_dim (stmt);
+	  break;
 	case IFN_UBSAN_CHECK_ADD:
 	  subcode = PLUS_EXPR;
 	  break;

  reply	other threads:[~2015-11-05 15:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-28 18:41 Nathan Sidwell
2015-11-02 13:56 ` Nathan Sidwell
2015-11-04 10:02   ` Bernd Schmidt
2015-11-05 15:48     ` Nathan Sidwell [this message]
2015-11-08 14:04       ` Thomas Schwinge
2015-11-08 15:44         ` Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=563B7A32.7010209@acm.org \
    --to=nathan@acm.org \
    --cc=bschmidt@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).