diff mbox

[OpenACC] internal fn folding

Message ID 563116AC.3010108@acm.org
State New
Headers show

Commit Message

Nathan Sidwell Oct. 28, 2015, 6:40 p.m. UTC
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?

nathan

Comments

Nathan Sidwell Nov. 2, 2015, 1:56 p.m. UTC | #1
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?

https://gcc.gnu.org/ml/gcc-patches/2015-10/threads.html#03095

Ping?


nathan
Bernd Schmidt Nov. 4, 2015, 10:02 a.m. UTC | #2
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?
>
> https://gcc.gnu.org/ml/gcc-patches/2015-10/threads.html#03095
>
> Ping?

Ok.


Bernd
diff mbox

Patch

2015-10-28  Nathan Sidwell  <nathan@codesourcery.com>

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

Index: gcc/gimple-fold.c
===================================================================
--- gcc/gimple-fold.c	(revision 229488)
+++ gcc/gimple-fold.c	(working copy)
@@ -64,6 +64,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.
@@ -2925,6 +2926,40 @@  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 (gimple *call)
+{
+  tree size = integer_one_node;
+
+  if (tree attrs = get_oacc_fn_attrib (current_function_decl))
+    {
+      tree arg = gimple_call_arg (call, 0);
+      tree pos = TREE_VALUE (attrs);
+
+      for (unsigned axis = (unsigned) TREE_INT_CST_LOW (arg); axis--;)
+	pos = TREE_CHAIN (pos);
+      size = TREE_VALUE (pos);
+    }
+
+  tree result;
+  if (integer_zerop (size))
+    /* Dimension size is dynamic.  */
+    result = NULL_TREE;
+  else if (gimple_call_internal_fn (call) == IFN_GOACC_DIM_SIZE)
+    result = size;
+  else if (integer_onep (size))
+    /* Size is one, so pos must be zero.  */
+    result = integer_zero_node;
+  else
+    /* Size is more than 1, so POS might be non-zero.  */
+    result = NULL_TREE;
+
+  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.  */
@@ -3125,6 +3160,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;