[GSoC] type of an isl_ast_expr_id
Roman Gareev
gareevroman@gmail.com
Tue Jul 29 10:46:00 GMT 2014
I've tested Graphite with the ISL AST generator as the main code
generator and found out the following problem: in the current
implementation the gcc_expression_from_isl_ast_expr_id can return a
tree of a type, which doesn't correspond to the type chosen for
graphite expressions.
If we try, for example, to generate Gimple code from the following ISL AST:
if (J >= 1) {
for (int c1 = 0; c1 < min(N, J); c1 += 1) {
for (int c3 = 0; c3 < min(J, N); c3 += 1)
S_10(c1, c3);
for (int c3 = J + 1; c3 < N; c3 += 1)
S_10(c1, c3);
}
for (int c1 = J + 1; c1 < N; c1 += 1) {
for (int c3 = 0; c3 < J; c3 += 1)
S_10(c1, c3);
for (int c3 = J + 1; c3 < N; c3 += 1)
S_10(c1, c3);
}
} else
for (int c1 = 1; c1 < N; c1 += 1)
for (int c3 = 1; c3 < N; c3 += 1)
S_10(c1, c3);
(It's generated from id-10.c)
we'll get the following error:
id-10.c: In function ‘foo’:
id-10.c:4:1: internal compiler error: in fold_binary_loc, at fold-const.c:10692
foo (int N, unsigned int J)
^
0x7cff3a fold_binary_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*)
/home/roman/sec_trunk/gcc/gcc/fold-const.c:10692
0x7d646a fold_build2_stat_loc(unsigned int, tree_code, tree_node*,
tree_node*, tree_node*)
/home/roman/sec_trunk/gcc/gcc/fold-const.c:15023
0xf010e8 nary_op_to_tree
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:290
0xf010e8 gcc_expression_from_isl_expr_op
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:317
0xf010e8 gcc_expression_from_isl_expression
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:364
0xf00f57 binary_op_to_tree
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:170
0xf00f57 gcc_expression_from_isl_expr_op
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:333
0xf00f57 gcc_expression_from_isl_expression
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:364
0xf018d0 graphite_create_new_loop_guard
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:523
0xf018d0 translate_isl_ast_node_for
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:558
0xf018d0 translate_isl_ast
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:704
0xf017b0 translate_isl_ast_node_block
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:646
0xf017b0 translate_isl_ast
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:715
0xf01702 translate_isl_ast_node_if
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:679
0xf01702 translate_isl_ast
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:708
0xf027d7 graphite_regenerate_ast_isl(scop*)
/home/roman/sec_trunk/gcc/gcc/graphite-isl-ast-to-gimple.c:893
0xefce8f graphite_transform_loops()
/home/roman/sec_trunk/gcc/gcc/graphite.c:304
0xefcf10 graphite_transforms
/home/roman/sec_trunk/gcc/gcc/graphite.c:333
0xefcf10 execute
/home/roman/sec_trunk/gcc/gcc/graphite.c:413
It is caused by difference in precisions of arguments in the min
expression. The attached patch may fix this.
I've also found out that pr35356-2.c is no longer suitable for
testing. The following CLooG AST
for (scat_1=0;scat_1<=min(k_6-1,n_5-1);scat_1++) {
(scat_1);
}
if ((k_6 >= 0) && (n_5 >= k_6+1)) {
(k_6);
}
for (scat_1=max(0,k_6+1);scat_1<=n_5-1;scat_1++) {
(scat_1);
}
is generated from its source code
int a[100];
int
foo (int bar, int n, int k)
{
int i;
for (i = 0; i < n; i++)
if (i == k)
a[i] = 1;
else
a[i] = i;
return a[bar];
}
The test checks that the dump file contains four MIN_EXPR and four MAX_EXPR
/* { dg-final { scan-tree-dump-times "MIN_EXPR\[^\\n\\r]*;" 4 "graphite" } } */
/* { dg-final { scan-tree-dump-times "MAX_EXPR\[^\\n\\r]*;" 4 "graphite" } } */
However, the ISL AST generated from this code
if (k >= 1) {
for (int c1 = 0; c1 < n; c1 += 1)
if (c1 >= k + 1) {
S_7(c1);
} else if (k >= c1 + 1) {
S_7(c1);
} else
S_6(k);
} else {
if (k == 0)
S_6(0);
for (int c1 = max(k + 1, 0); c1 < n; c1 += 1)
S_7(c1);
}
doesn't contain min expression at all.
Should we remove /* { dg-final { scan-tree-dump-times
"MIN_EXPR\[^\\n\\r]*;" 4 "graphite" } } */ from this test case?
P.S.: The other graphite tests (except vect-pr43423.c) are passed by
graphite in case we run it with the ISL AST generator.
--
Cheers, Roman Gareev.
-------------- next part --------------
2014-07-29 Roman Gareev <gareevroman@gmail.com>
[gcc/]
* graphite-isl-ast-to-gimple.c:
(gcc_expression_from_isl_ast_expr_id): Add calling of fold_convert.
(gcc_expression_from_isl_expression): Pass type to
gcc_expression_from_isl_ast_expr_id.
-------------- next part --------------
Index: gcc/graphite-isl-ast-to-gimple.c
===================================================================
--- gcc/graphite-isl-ast-to-gimple.c (revision 213109)
+++ gcc/graphite-isl-ast-to-gimple.c (working copy)
@@ -125,7 +125,8 @@
expression (an isl_ast_expr of type isl_ast_expr_id). */
static tree
-gcc_expression_from_isl_ast_expr_id (__isl_keep isl_ast_expr *expr_id,
+gcc_expression_from_isl_ast_expr_id (tree type,
+ __isl_keep isl_ast_expr *expr_id,
ivs_params &ip)
{
gcc_assert (isl_ast_expr_get_type (expr_id) == isl_ast_expr_id);
@@ -136,7 +137,7 @@
gcc_assert (res != ip.end () &&
"Could not map isl_id to tree expression");
isl_ast_expr_free (expr_id);
- return res->second;
+ return fold_convert (type, res->second);
}
/* Converts an isl_ast_expr_int expression E to a GCC expression tree of
@@ -351,7 +352,7 @@
switch (isl_ast_expr_get_type (expr))
{
case isl_ast_expr_id:
- return gcc_expression_from_isl_ast_expr_id (expr, ip);
+ return gcc_expression_from_isl_ast_expr_id (type, expr, ip);
case isl_ast_expr_int:
return gcc_expression_from_isl_expr_int (type, expr);
More information about the Gcc-patches
mailing list