diff mbox

[GSoC] Handling of isl_ast_op_pdiv_q and isl_ast_op_pdiv_r

Message ID CABGF_gcRNvfVHZ0Xb1_uiEGg98cvhexbvi7PbgU65vpjV4=y7g@mail.gmail.com
State New
Headers show

Commit Message

Roman Gareev July 23, 2014, 2:55 p.m. UTC
I've attached the patch, which adds handling of isl_ast_op_pdiv_q and
isl_ast_op_pdiv_r. It also contains a corresponding test case, which
generates the following ISL AST:

{
  for (int c1 = 0; c1 < -((-k.0 + i + 4294967296) % 4294967296) +
4294967296; c1 += 1)
    S_4(c1);
  S_6();
}

Is it fine for trunk?

--
                                   Cheers, Roman Gareev.
2014-07-23  Roman Gareev  <gareevroman@gmail.com>

[gcc/]

	* graphite-isl-ast-to-gimple.c:
	(binary_op_to_tree): Add new cases.
	(gcc_expression_from_isl_expr_op): Move isl_ast_op_pdiv_q,
	isl_ast_op_pdiv_r to different cases.

[gcc/testsuite]

	* gcc.dg/graphite/isl-ast-gen-blocks-3.c: New testcase.

Comments

Tobias Grosser July 23, 2014, 3:23 p.m. UTC | #1
On 23/07/2014 16:55, Roman Gareev wrote:
> I've attached the patch, which adds handling of isl_ast_op_pdiv_q and
> isl_ast_op_pdiv_r. It also contains a corresponding test case, which
> generates the following ISL AST:
>
> {
>    for (int c1 = 0; c1 < -((-k.0 + i + 4294967296) % 4294967296) +
> 4294967296; c1 += 1)
>      S_4(c1);
>    S_6();
> }
>
> Is it fine for trunk?

Some minor comments in the test case, otherwise LGTM. Feel free to 
commit after addressing those.

> Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-blocks-3.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-blocks-3.c	(revision 0)
> +++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-blocks-3.c	(working copy)
> @@ -0,0 +1,27 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */
> +
> +int k = 50;

Any reason you don't make 'k' a function parameter?

> +static int __attribute__((noinline))
> +foo ()
> +{
> +  int i, res;
> +  for (i = k/2, res = 0; i < k; i++)

Can you initialize res outside of the loop?

Cheers,
Tobias
Roman Gareev July 24, 2014, 10:09 a.m. UTC | #2
> Any reason you don't make 'k' a function parameter?

Yes, ISL'll generate the following code, if 'k' a function parameter:

for (int c1 = 0; c1 <= 24; c1 += 1)
  S_3(c1);

However, we could use  -fno-ipa-cp to get the ISL AST, which contains
isl_ast_op_pdiv_r. What do you think about this?

> Can you initialize res outside of the loop?

Yes, I've implemented this in the improved version.

--
                                   Cheers, Roman Gareev.
Tobias Grosser July 24, 2014, 10:30 a.m. UTC | #3
On 24/07/2014 12:09, Roman Gareev wrote:
>> Any reason you don't make 'k' a function parameter?
>
> Yes, ISL'll generate the following code, if 'k' a function parameter:
>
> for (int c1 = 0; c1 <= 24; c1 += 1)
>    S_3(c1);
>
> However, we could use  -fno-ipa-cp to get the ISL AST, which contains
> isl_ast_op_pdiv_r. What do you think about this?

I see. Just add a comment that we use globals to avoid ipa-cp.

>> Can you initialize res outside of the loop?
>
> Yes, I've implemented this in the improved version.

Nice. Feel free to commit.

Tobias
diff mbox

Patch

Index: gcc/graphite-isl-ast-to-gimple.c
===================================================================
--- gcc/graphite-isl-ast-to-gimple.c	(revision 212922)
+++ gcc/graphite-isl-ast-to-gimple.c	(working copy)
@@ -186,6 +186,12 @@ 
     case isl_ast_op_div:
       return fold_build2 (EXACT_DIV_EXPR, type, tree_lhs_expr, tree_rhs_expr);
 
+    case isl_ast_op_pdiv_q:
+      return fold_build2 (TRUNC_DIV_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+
+    case isl_ast_op_pdiv_r:
+      return fold_build2 (TRUNC_MOD_EXPR, type, tree_lhs_expr, tree_rhs_expr);
+
     case isl_ast_op_fdiv_q:
       return fold_build2 (FLOOR_DIV_EXPR, type, tree_lhs_expr, tree_rhs_expr);
 
@@ -299,8 +305,6 @@ 
     case isl_ast_op_call:
     case isl_ast_op_and_then:
     case isl_ast_op_or_else:
-    case isl_ast_op_pdiv_q:
-    case isl_ast_op_pdiv_r:
     case isl_ast_op_select:
       gcc_unreachable ();
 
@@ -312,6 +316,8 @@ 
     case isl_ast_op_sub:
     case isl_ast_op_mul:
     case isl_ast_op_div:
+    case isl_ast_op_pdiv_q:
+    case isl_ast_op_pdiv_r:
     case isl_ast_op_fdiv_q:
     case isl_ast_op_and:
     case isl_ast_op_or:
Index: gcc/testsuite/gcc.dg/graphite/isl-ast-gen-blocks-3.c
===================================================================
--- gcc/testsuite/gcc.dg/graphite/isl-ast-gen-blocks-3.c	(revision 0)
+++ gcc/testsuite/gcc.dg/graphite/isl-ast-gen-blocks-3.c	(working copy)
@@ -0,0 +1,27 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 -fgraphite-identity -fgraphite-code-generator=isl" } */
+
+int k = 50;
+static int __attribute__((noinline))
+foo ()
+{
+  int i, res;
+  for (i = k/2, res = 0; i < k; i++)
+    res += i;
+
+  return res;
+}
+
+extern void abort ();
+
+int
+main (void)
+{ 
+  int res = foo ();
+
+
+  if (res != 925)
+    abort ();
+
+  return 0;
+}